爲什麼本地搭建一個git服務器
- 對於自己學習使用的代碼,在沒有網絡的情況下不能用github,gitlab,所以本地建立一個git服務器。
git服務器環境準備centos7
服務端創建git用戶
id git
useradd git
passwd git
輸入密碼,我設置的是xxx@123
客戶端開啓公鑰認證認證,免密push/pull
vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
如果是centos7.4以上(含7.4),ssh1已經不支持了,只支持ssh2代協議。所以RSAAuthentication項是沒有的
- 客戶端執行 執行ssh-keygen -t rsa 生成公鑰和私鑰
- 複製客戶端公鑰到服務器端ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
服務端創建git倉庫
mkdir -p /data/git/gittest.git
cd /data/git/gittest.git
git init --bare .
chown -R git:git /data/git
客戶端clone遠程倉庫
mkdir localgit
cd localgit
git clone [email protected]:/data/git/gittest.git .
touch abc.txt
git add .
git commit -m 'aaa'
git push