SSH公钥免密不能登录
问题
设置SSH公钥免密码登陆时,已经设置PubkeyAuthentication yes以及.ssh/authorized_keys,仍然不能正常登录,报错:
Authentication refused: bad ownership or modes
跟踪
登陆目标机器,查看sshd的日志信息。日志信息目录为/var/log/secure,会发现如下字样的日志信息:
# tail -f /var/log/secure
May 22 10:12:21 kec-web sshd[10885]: reprocess config line 43: Deprecated option RSAAuthentication
May 22 10:12:21 kec-web sshd[10885]: Authentication refused: bad ownership or modes for directory /home/yezhou/.ssh
May 22 10:12:22 kec-web sshd[10885]: Connection closed by 172.26.0.12 port 23058 [preauth]
原因及解决
原因分析
sshd为了安全,对属主的目录和文件权限有所要求。如果权限不对,则ssh的免密码登陆不生效。
- 用户目录权限为
755或者700,就是不能是77x .ssh目录权限一般为755或者700rsa_id.pub及authorized_keys权限一般为644rsa_id权限必须为600
解决方法
检测目录权限,把不符合要求的按要求设置权限即可。




