- 客户端生成公钥,一直按回车.运行结束后.ssh目录下生成两个文件,id_rsa.pub为公钥,id_rsa为私钥
ssh -keygen
- 定位到客户端的.ssh目录下,将公钥传送到远程主机上
ssh-copy-id root@your_ip
- 密码方式登录远程主机,查看 /etc/ssh/sshd_config 文件,确认是否开启允许密钥登录模式
PermitRootLogin yes
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
尝试密钥登录。确认密钥登录成功后,关闭密码登录(远程主机/etc/ssh/sshd_config 文件)
PasswordAuthentication no
重启远程主机ssh服务
service sshd restart