環(huán)境:
服務(wù)器 CentOS6.6 + git(version 1.7.1)
客戶端 Windows10 + git(version 2.8.4.windows.1)
① 安裝 Git
Linux 做為服務(wù)器端系統(tǒng),Windows 作為客戶端系統(tǒng),分別安裝 Git
服務(wù)器端:
#yum install -y git
安裝完后,查看 Git 版本
[root@localhost ~]# git --versiongit version 1.7.1
客戶端:
下載 Git for Windows,地址:https://git-for-windows.github.io/
安裝完之后,可以使用 Git Bash 作為命令行客戶端。
安裝完之后,查看 Git 版本
$ git --versiongit version 2.8.4.windows.1
② 服務(wù)器端創(chuàng)建 git 用戶,用來(lái)管理 Git 服務(wù),并為 git 用戶設(shè)置密碼
[root@localhost home]# id gitid: git:無(wú)此用戶[root@localhost home]# useradd git[root@localhost home]# passwd git
③ 服務(wù)器端創(chuàng)建 Git 倉(cāng)庫(kù)
設(shè)置 /home/data/git/gittest.git 為 Git 倉(cāng)庫(kù)
然后把 Git 倉(cāng)庫(kù)的 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/
④ 客戶端 clone 遠(yuǎn)程倉(cāng)庫(kù)
進(jìn)入 Git Bash 命令行客戶端,創(chuàng)建項(xiàng)目地址(設(shè)置在 d:/wamp64/www/gittest_gitbash)并進(jìn)入:
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$
然后從 Linux Git 服務(wù)器上 clone 項(xiàng)目:
$ git clone git@192.168.56.101:/home/data/gittest.git
當(dāng)?shù)谝淮芜B接到目標(biāo) Git 服務(wù)器時(shí)會(huì)得到一個(gè)提示:
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.
此時(shí) C:/Users/用戶名/.ssh 下會(huì)多出一個(gè)文件 known_hosts,以后在這臺(tái)電腦上再次連接目標(biāo) Git 服務(wù)器時(shí)不會(huì)再提示上面的語(yǔ)句。

后面提示要輸入密碼,可以采用 SSH 公鑰來(lái)進(jìn)行驗(yàn)證。
⑤ 客戶端創(chuàng)建 SSH 公鑰和私鑰
$ ssh-keygen -t rsa -C

此時(shí) C:/Users/用戶名/.ssh 下會(huì)多出兩個(gè)文件 id_rsa 和 id_rsa.pub
id_rsa 是私鑰
id_rsa.pub 是公鑰

⑥ 服務(wù)器端 Git 打開(kāi) RSA 認(rèn)證
進(jìn)入 /etc/ssh 目錄,編輯 sshd_config,打開(kāi)以下三個(gè)配置的注釋:
RSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keys
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注