- 安裝git
- yum install -y git
- 創建git用戶
- 新建用戶:adduser git
- 設置密碼:passwd git
- 初始化git倉庫,路徑:/opt/repos/testgit.git
- 創建路徑:mkdir /opt/repos
- 創建路徑:mkdir /opt/repos/testgit.git
- 切換到路徑:cd /opt/repos/
- 初始化倉庫:git init --bare testgit.git
- 修改倉庫的所有者:chown git:git testgit.git -R
- 在客戶端拉取分支代碼
- git clone [email protected]:/opt/repos/testgit.git
- 注意:如果服務器ssh連接的端口默認值不是22,需要指定端口號,例如我的端口號是29560
- git clone ssh://[email protected]:29560/opt/repos/testgit.git
- 配置免密操作
- 在客戶端創建SSH Key
- 打開Shell(windows 下打開Git Bash)
- ssh-keygen -t rsa -C "[email protected]"
- 執行完畢後會在C:\Users\用戶\.ssh目錄(Windows) 生成 id_rsa和id_rsa.pub 這兩個文件,我們需要用到的是公鑰id_rsa.pub
- 在Git 服務器配置RSA
- 切換到/etc/ssh目錄: cd /etc/ssh
- 打開文件:vi sshd_config
- 把以下3行開頭的#去掉
-
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys
-
- 切換到/home/git/:cd /home/git/
- 創建.ssh: mdkir .ssh
- 修改權限:chmod 700 .ssh
- 切換到.ssh: cd .ssh
- 創建authorized_keys: vi authorized_keys
- 修改權限:chmod 600 authorized_keys
- 把剛纔生成的公鑰id_rsa.pub的內容添加到authorized_keys裏
- 在客戶端創建SSH Key
CentOS 安裝Git 服務器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.