情景:A能无密码访问B,C,B,C不能无密码访问A
原因分析:使用B尝试登录A,不要输入密码,直接确认,查看A的日志,/var/log/auth.log,发现如下:
Authentication refused: bad ownership or modes for directory /home/hadoop
这说明权限出现问题,因此需要全方位(A,B,C的所有相关权限)排查,均设置如下权限:
1. home/hadoop权限:
设置之后Authentication refused: bad ownership or modes for directory /home/hadoop问题消失
2. ~/.ssh权限(全目录为/home/hadoop/.ssh)
sudo chmod 755 .ssh
cd ~/.ssh
sudo chmod 644 authorized_keys
如果不放心,可以再设置:
rsa_id.pub 及authorized_keys权限一般为644
rsa_id权限必须为600
3. 重启ssh
/etc/init.d/sshd restart
4. ssh-add
5. 尝试互相登录,看到可以互相无密码访问了。
注:
1. 在配置ssh无密码访问的过程中会出现一些warning,可以直接无视,dd的时候:
Could not open a connection to your authentication agent
可以输入如下命令:eval `ssh-agent` 之后再输入ssh-add,不过即使不这么做,也是会成功的没有影响。
2. 小编已经和队友无数次遇到各种谁登录不了谁的问题了,要学会查看日志,以便排查问题,其次是权限问题对于ssh真的很重要。
终极参考:
www.bo56.com/ssh免密码登陆设置时authentication-refused-bad-ownership-or-modes错误解决方法/
以上链接中如下文字非常有用:
sshd为了安全,对属主的目录和文件权限有所要求。如果权限不对,则ssh的免密码登陆不生效。
用户目录权限为 755 或者 700,就是不能是77x。
.ssh目录权限一般为755或者700。
rsa_id.pub 及authorized_keys权限一般为644
rsa_id权限必须为600