標籤:
配置SSH無密碼登入需要3步:
1.產生公開金鑰和私密金鑰
2.匯入公開金鑰到認證檔案,更改許可權
3.測試
1.產生公開金鑰和私密金鑰Shell代碼
- ssh-keygen -t dsa -P ‘‘ -f ~/.ssh/id_dsa
預設在 ~/.ssh目錄產生兩個檔案:
id_rsa :私密金鑰
id_rsa.pub :公開金鑰
2.匯入公開金鑰到認證檔案 2.1 匯入本機Shell代碼
- cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
2.2 匯入要免密碼登入的伺服器
首先將認證檔案複製到伺服器
Shell代碼
- scp ~/.ssh/authorized_keys [email protected]主機名稱:/home/xxx/.ssh/
一般以上幾步就ok了,但我的仍要輸入密碼,
用root使用者登陸查看系統的記錄檔:$tail /var/log/secure -n 20
…………
Oct 7 10:26:43 MasterServer sshd[2734]: Authentication refused: bad ownership or modes for file /home/hadooper/.ssh/authorized_keys
Oct 7 10:26:48 MasterServer sshd[2734]: Accepted password for hadooper from ::1 port 37456 ssh2
Oct 7 10:26:48 MasterServer sshd[2734]: pam_unix(sshd:session): session opened for user hadooper by (uid=0)
Oct 7 10:36:30 MasterServer sshd[2809]: Accepted password for hadooper from 192.168.1.241 port 36257 ssh2
Oct 7 10:36:30 MasterServer sshd[2809]: pam_unix(sshd:session): session opened for user hadooper by (uid=0)
Oct 7 10:38:28 MasterServer sshd[2857]: Authentication refused: bad ownership or modes for directory /home/hadooper/.ssh
…………
提示/home/hadooper/.ssh和 /home/hadooper/.ssh/authorized_keys許可權不對,修改如下: Shell代碼
- chmod 700 ~/.ssh
- chmod 600 ~/.ssh/authorized_keys
3.測試
ssh host,第一次登入可能需要yes確認,之後就可以直接登入了。
轉自: http://blog.csdn.net/hwwn2009/article/details/39852457
centos配置ssh免密碼登入後,仍提示輸入密碼