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 \\ 重启服务