1.生成公鑰私鑰
ssh-genkey -t rsa
2.複製公鑰到其他主機
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
該命令實際是將公鑰放到~/.ssh/authorized_keys文件中文件中,也可以使用
將公鑰複製到對方主機scp /root/.ssh/id_rsa.pub 192.168.171.101:/tmp
在另外主機上cat /tmp/id_rsa.pub ~/.ssh/authorized_keys即可
如果沒有ssh-copy-id命令則安裝openssh-clients包即可
常見問題:
1、生成密鑰並上傳至遠程主機後,仍然無法實現無密碼登錄?
打開遠程主機的 /etc/ssh/sshd_config 這個文件,以下幾行取消註釋。
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
重啓sshd服務