1.使用ssh-keygen -t rsa命令,生成一个rsa密钥对,一路回车即可。
默认生成的密钥文件在root/.ssh目录下。
ssh-keygen -t rsa

2.检查下.ssh目录下authorized_keys文件是否存在,没有的话,创建一个,然后将id_rsa.pub的内容追加到authorized_keys文件尾。
cd .ssh
cat id_rsa.pub >> authorized_keys

3.修改.ssh的权限为700
, authorized_keys的权限为600或者更严格的400
,否则登录的时候会提示server refuse you key。
chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

4.修改ssh的配置
vim /etc/ssh/sshd_config
#CentOS7.4相对于之前版本,做了一些与sshd相关的安全更新来加强sshd的安全性。其中之一就是弃用RSAAuthentication支持,anolis8.8也不需要添加RSAAuthentication

5.将/root/.ssh/id_rsa文件保存在本地(可将文件名修改成任意名.pem结尾的文件)
6.重启sshd服务验证密钥是否能登录
systemctl restart sshd
7.禁用密码登录
vim /etc/ssh/sshd_config

将PasswordAuthentication 设置为no,保存退出后重启服务器
8.linux上ssh连接服务器
把私钥214root.pem文件
复制到客户机上,使用ssh root@192.168.8.124 -i 214root.pem命令进行登录

这个错误表明私钥文件的权限设置过于宽松,安全性不足,因此SSH拒绝使用它进行连接。修改密钥文件权限为400即可