Centos 6.5下部署GIT 服務,客戶端安裝實施過程及常見問題處理

一、安裝

#yum install -y git

二、客戶端安裝

下載 Git for Windows,地址:https://git-for-windows.github.io/

三、服務端配置

1、服務器端創建 git 用戶,用來管理 Git 服務,併爲 git 用戶設置密碼

[root@localhost home]# id gitid: git:無此用戶[root@localhost home]# useradd git[root@localhost home]# passwd git


2、服務器端創建 Git 倉庫

設置 /home/data/git/gittest.git 爲 Git 倉庫

然後把 Git 倉庫的 owner 修改爲 git

[root@localhost home]# mkdir -p data/git/gittest.git[root@localhost home]# git init --bare data/git/gittest.gitInitialized empty Git repository in /home/data/git/gittest.git/

[root@localhost home]# cd data/git/

[root@localhost git]# chown -R git:git gittest.git/


四、客戶端操作配置

1、進入 Git Bash 命令行客戶端,創建項目地址(設置在 d:/wamp64/www/gittest_gitbash)並進入:

dee@Lenovo-PC MINGW64 /d$ cd wamp64/wwwdee@Lenovo-PC MINGW64 /d/wamp64/www$ mkdir gittest_gitbashdee@Lenovo-PC MINGW64 /d/wamp64/www$ cd gittest_gitbashdee@Lenovo-PC MINGW64 /d/wamp64/www/gittest_gitbash$


2、然後從 Linux Git 服務器上 clone 項目:

$ git clone [email protected]:/home/data/gittest.git


當第一次連接到目標 Git 服務器時會得到一個提示:

The authenticity of host '192.168.56.101 (192.168.56.101)' can't be established.RSA key fingerprint is SHA256:Ve6WV/SCA059EqoUOzbFoZdfmMh3B259nigfmvdadqQ.Are you sure you want to continue connecting (yes/no)?

選擇 yes:

Warning: Permanently added '192.168.56.101' (RSA) to the list of known hosts.


3、此時 C:\Users\用戶名\.ssh 下會多出一個文件 known_hosts,以後在這臺電腦上再次連接目標 Git 服務器時不會再提示上面的語句。

五、客戶端創建公匙

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

此時 C:\Users\用戶名\.ssh 下會多出兩個文件 id_rsa 和 id_rsa.pub

id_rsa 是私鑰

id_rsa.pub 是公鑰

六、服務端GIT打開RSA認證

1、

進入 /etc/ssh 目錄,編輯 sshd_config,打開以下三個配置的註釋:

RSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keys

保存並重啓 sshd 服務:

[root@localhost ssh]# /etc/rc.d/init.d/sshd restart

由 AuthorizedKeysFile 得知公鑰的存放路徑是 .ssh/authorized_keys,實際上是 $Home/.ssh/authorized_keys,由於管理 Git 服務的用戶是 git,所以實際存放公鑰的路徑是 /home/git/.ssh/authorized_keys

在 /home/git/ 下創建目錄 .ssh

[root@localhost git]# pwd/home/git[root@localhost git]# mkdir .ssh[root@localhost git]# ls -a . .. .bash_logout .bash_profile .bashrc .gnome2 .mozilla .ssh

然後把 .ssh 文件夾的 owner 修改爲 git


[root@localhost git]# chown -R git:git .ssh[root@localhost git]# ll -a總用量 32drwx------. 5 git  git  4096 8月  28 20:04 .drwxr-xr-x. 8 root root 4096 8月  28 19:32 ..-rw-r--r--. 1 git  git    18 10月 16 2014 .bash_logout-rw-r--r--. 1 git  git   176 10月 16 2014 .bash_profile-rw-r--r--. 1 git  git   124 10月 16 2014 .bashrcdrwxr-xr-x. 2 git  git  4096 11月 12 2010 .gnome2drwxr-xr-x. 4 git  git  4096 5月   8 12:22 .mozilladrwxr-xr-x. 2 git  git  4096 8月  28 20:08 .ssh


2、將客戶端公鑰導入服務器端 /home/git/.ssh/authorized_keys 文件

回到 Git Bash 下,導入文件:

$ ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

回到服務器端,查看 .ssh 下是否存在 authorized_keys 文件:

[root@localhost git]# cd .ssh[root@localhost .ssh]# ll總用量 4-rw-rw-r--. 1 git git 398 8月  28 20:08 authorized_keys

可以查看一下是否是客戶端生成的公鑰。

 

重要:

修改 .ssh 目錄的權限爲 700

修改 .ssh/authorized_keys 文件的權限爲 600

[root@localhost git]# chmod 700 .ssh[root@localhost git]# cd .ssh[root@localhost .ssh]# chmod 600 authorized_keys


3、客戶端在此clone遠程倉庫

$ git clone [email protected]:/home/data/git/gittest.git

也可以使用 tortoiseGit 客戶端來管理項目


備註:

1、以上資源出處:http://www.cnblogs.com/dee0912/p/5815267.html

2、tortoiseGit配置:http://www.mamicode.com/info-detail-423481.html

3、常見問題處理:https://my.oschina.net/psuyun/blog/123005

我就是按照以上方法安裝測試完成,當時遇到128錯誤碼,萬一你也遇到這種情況,可以檢查下 公匙是否導入到服務端,服務端git倉庫是否建立成功,以及檢查git倉庫的權限。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章