1. 程式人生 > >使用ssh key 免密碼登錄

使用ssh key 免密碼登錄

ssh

1,生成SSH公鑰和私鑰

ssh-keygen -t rsa
Enter file in which to save the key (/root/.ssh/id_rsa):  \\回車使用默認路徑
Enter passphrase (empty forno passphrase):               \\使用私鑰登錄時候的密碼(建議留空)
Enter same passphrase again:                                       \\重復短語密碼
Your identification has been saved in/root/.ssh/id_rsa.
Yourpublic key has been saved in/root/.ssh/id_rsa.pub.
(顯示生成公鑰和私鑰的路徑)

2,添加公鑰到相關服務器裏
打開剛才生成的.pub文件,復制裏面內容 , 在服務器裏面輸入

echo "XXX(.pub裏面所有的內容)" >> /root/.ssh/authorized_keys

3,編輯sshd_config文件

vi /etc/ssh/sshd_config
###############################################
PasswordAuthentication no \\禁用密碼驗證
RSAAuthentication yes
PubkeyAuthentication yes   \\啟用私鑰驗證
service sshd restar            \\ 重啟服務

使用ssh key 免密碼登錄