SSH免密登录配置成功后不生效问题

问题

已经将主机的公钥id_rsa.pub追加到了远端主机的authorized_keys文件中,且文件权限均为 600
但是仍然无法免密登录,只能使用密码登录

日志

# tail /var/log/secure
Dec  7 15:54:17 image sshd[5558]: Disconnected from 10.171.122.85 port 38000
Dec  7 15:54:17 image sshd[5558]: pam_unix(sshd:session): session closed for user root
Dec  7 15:54:20 image sshd[5579]: reprocess config line 50: Deprecated option RSAAuthentication
Dec  7 15:54:20 image sshd[5579]: Authentication refused: bad ownership or modes for directory /root
Dec  7 15:54:36 image sshd[5579]: Accepted password for root from 10.171.122.85 port 38006 ssh2
Dec  7 15:54:36 image sshd[5579]: pam_unix(sshd:session): session opened for user root by (uid=0)
Dec  7 15:54:37 image sshd[5579]: Received disconnect from 10.171.122.85 port 38006:11: disconnected by user
Dec  7 15:54:37 image sshd[5579]: Disconnected from 10.171.122.85 port 38006
Dec  7 15:54:37 image sshd[5579]: pam_unix(sshd:session): session closed for user root
Dec  7 15:57:01 image sshd[5905]: reprocess config line 50: Deprecated option RSAAuthentication
Dec  7 15:57:01 image sshd[5905]: Accepted publickey for root from 10.171.122.85 port 38106 ssh2: RSA SHA256:1A8dDgEnM7OQxIySYUWzipuF6boKrYlT2zjYFjyA1sE
Dec  7 15:57:01 image sshd[5905]: pam_unix(sshd:session): session opened for user root by (uid=0)

image

解决

用户家目录权限被篡改为非用户属组,需要更改为指定的用户权限,且用户目录组权限不能有 W 权限

chmod g-w /home/user
chmod 700 ./.ssh 
chmod 600 ~/.ssh/authorized_keys

-PS

linux下免密认证登录失败原因总结

posted @ 2021-12-07 18:53  AlexG  阅读(1030)  评论(0编辑  收藏  举报