客户端生成公钥和私钥,在 root/.ssh/:
#直接回车
ssh-keygen -t rsa
生成的公钥上传服务器:
scp /root/id_rsa.pub root@xxx.xxx.xxx.xxx:/root
服务端公钥保存在哪个用户的目录下,就是用哪个用户登录
cat /root/id_rsa.pub >>/root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
修改服务器端ssh配置文件
vim /etc/ssh/sshd_config
添加以下内容
RSAAuthentication yes # 开启rsa验证
PubkeyAuthentication yes # 是否使用公钥
AuthorizedKeysFile .ssh/authorized_keys # 公钥保存位置
PasswordAuthentication no # 禁止使用密码登录,选择性开启
重启服务
service sshd restart
客户端登录
ssh root@xxx.xxx.xxx.xxx