ssh免密碼設置

服務器端sshd啓動

/etc/init.d/sshd start

在本機器中的用戶目錄/root/.ssh/目錄下執行下命令

ssh-keygen


提示輸入密碼,直接回車(沒有密碼)。

將生成兩個文件,id_rsa和id_rsa.pub。

 
如下:

 

[root@localhost .ssh]# ssh-keygen
Generating public/private rsa key pair. 
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):            <-- 輸入登陸的密碼 不輸入表示可以不用密碼登陸 
Enter same passphrase again:                                    <-- 輸入登陸的密碼
Your identification has been saved in /root/.ssh/id_rsa. 
Your public key has been saved in /root/.ssh/id_rsa.pub. 
The key fingerprint is: 
2d:c2:1e:59:43:61:b6:c3:89:1e:92:c4:92:a4:48:d9 
[email protected]

 

2、 將id_rsa.pub拷貝到遠程機器,並且將id_rsa.pub的內容複雜到/root/.ssh/中,並重命名爲authorized_keys(不能保留id_rsa.pub).

scp /root/.ssh/id_rsa.pub root@IP_ADD:/root/.ssh/authorized_keys

注意:目錄.ssh和文件authorized_keys的權限必須是600(安全問題)

完成這些工作後,用戶從“本地機器到遠程機器的登錄就不用密碼了”(如ssh登陸及scp傳輸文件等)。


ssh/下面不要有,id_rsa.pub.把id_rsa.pub內容加入到你要登錄的機器的authorized_keys 中就好,不要讓對方機器id_rsa.pub放在本機的.ssh/下面.,因爲本地id_rsa默認會和對方機器的id_rsa.pub驗證配對,如果id_rsa.pub不存在才驗證authorized_keys.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章