Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

Linux Mint 13 免密碼登入 Git 主機設定

以下記錄在 Linux Mint 13 上讓 Git 帳號可以免密碼登入的過程,這也是架 Gitolite 之前必須先打通的一關。

1. 服務端建立 git 帳號

sudo adduser --system --shell /bin/bash --group git
sudo adduser git ssh
sudo passwd git

2. 安裝並調整 SSH 設定

先安裝 open-ssh,接著修改 /etc/ssh/sshd_config。第一階段為了讓程序走一次密碼驗證,把相關欄位調整如下:

  • PermitRootLogin 設為 yes
  • PubkeyAuthentication 設為 no
  • 把 AuthorizedKeysFile .ssh/authorized_keys 那一行加上 # 註解掉
  • PasswordAuthentication 設為 yes

存檔後重啟服務:

sudo service ssh restart

3. 用戶端產生金鑰對

ssh-keygen -t rsa

4. 把公鑰送到遠端

用 ssh-copy-id 將公鑰複製到主機,這裡是從 skwiki 帳號複製到 git 帳號:

skwiki@HaSee$ ssh-copy-id -i ~/.ssh/id_rsa.pub git@localhost

這時會要求輸入 git 的密碼,輸入後 /home/git/.ssh/authorized_keys 裡就會寫入 id_rsa.pub 的內容。後續設定 Gitolite 時還會再動到這個檔案。

5. 二次修改 SSH 設定,關掉密碼登入

再次編輯 /etc/ssh/sshd_config:

  • PermitRootLogin 改為 yes
  • RSAAuthentication 設為 no
  • PubkeyAuthentication 設為 yes
  • AuthorizedKeysFile 那行加上 # 註解
  • PasswordAuthentication 設為 no
sudo service ssh restart

6. 用戶端驗證

ssh git@localhost

能直接進入而不必輸入密碼,就代表設定成功。補充一點:實務上 PasswordAuthentication 與 PubkeyAuthentication 可以同時為 yes,保留密碼登入作為金鑰失效時的後路,通常更安全也更保險。

Copyright © Linux教程網 All Rights Reserved