CentOS 安裝Git 服務器

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