CentOS搭建Git伺服器

2021-07-25 15:46:34 字數 2556 閱讀 8045

[root@localhost desktop]# yum install -y git

2、建立乙個git使用者,用來執行git服務

[root@localhost desktop]# useradd -r -s /bin/sh -c 'git version control' -d /home/git git

3、設定許可權

[root@localhost desktop]# mkdir -p /home/git
[root@localhost desktop]# chown git:git /home/git

4、初始化git倉庫:這裡我們選擇/data/git/learngit.git來作為我們的git倉庫

[root@localhost git]# git init --bare learngit.git

執行以上命令,會建立乙個裸倉庫,裸倉庫沒有工作區:

[root@localhost git]# chown git:git learngit.git

5、在這裡,git伺服器就已經搭得差不多了。下面我們在客戶端clone一下遠端倉庫

$ git clone [email protected]:/data/git/learngit.git

cloning into 'learngit'...

the authenticity of host '192.168.8.34 (192.168.8.34)' can't be established.

rsa key fingerprint is 2b:55:45:e7:4c:29:cc:05:33:78:03:bd:a8:cd:08:9d.

are you sure you want to continue connecting (yes/no)? yes

warning: permanently added '192.168.8.34' (rsa) to the list of known hosts.

[email protected]'s password:

這裡提示你輸入密碼才能clone,當然如果你知道密碼,可以鍵入密碼來進行clone,但是更為常見的方式,是利用ssh的公鑰來完成驗證。

6、客戶端建立ssh key

首先在使用者主目錄下,看看有沒有.ssh目錄,如果有,再看看這個目錄下有沒有id_rsa和id_rsa.pub這兩個檔案,如果已經有了,可直接跳到下一步。如果沒有,開啟shell(windows下開啟git bash),建立ssh key:

$ ssh-keygen -t rsa -c "[email protected]"

你需要把郵件位址換成你自己的郵件位址,然後一路回車,使用預設值即可,由於這個key也不是用於軍事目的,所以也無需設定密碼。

如果一切順利的話,可以在使用者主目錄裡找到.ssh目錄,裡面有id_rsa和id_rsa.pub兩個檔案,這兩個就是ssh key的秘鑰對,id_rsa是私鑰,不能洩露出去,id_rsa.pub是公鑰,可以放心地告訴任何人。

7、git伺服器開啟rsa認證

然後就可以去git伺服器上新增你的公鑰用來驗證你的資訊了。在git伺服器上首先需要將/etc/ssh/sshd_config中將rsa認證開啟,即:

1.rsaauthentication yes
2.pubkeyauthentication yes
3.authorizedkeysfile  .ssh/authorized_keys

這裡我們可以看到公鑰存放在.ssh/authorized_keys檔案中。所以我們在/home/git下建立.ssh目錄,然後建立authorized_keys檔案,並將剛生成的公鑰匯入進去。

然後再次clone的時候,或者是之後push的時候,就不需要再輸入密碼了:

$ git clone [email protected]:/data/git/learngit.git

CentOS 搭建Git伺服器

1,安裝openssh服務斷和客戶端 yum y install openssh 2,安裝git和python setuptools yum y install git python setuptools 3,獲取並安裝gitosis,來管理git倉庫 git clone cd gitosis py...

Centos搭建Git伺服器

1.安裝git centos安裝git只需要執行如下命令,直接安裝git yum install git2.建立git使用者 adduser git3.控制git使用者許可權,關掉bash許可權 vi etc passwd找到類似git x 1001 1001 home git bin bash 將...

CentOS搭建git伺服器

1.安裝 git 伺服器端 yum install y git安裝完後,檢視 git 版本 git version2.伺服器端建立 git 使用者,用來管理 git 服務,並為 git 使用者設定密碼 root localhost home id git id git 無此使用者 root loca...