问题:
在 linux 机器 10.0.0.1 上执行了命令 ssh-copy-id jenkins@10.0.0.2
配置免密登录后,执行ssh jenkins@10.0.0.2
登录 10.0.0.2 还是提示要输入密码
排查解决过程:
跟 sshd 服务相关的登录日志可以在 /var/log/secure 中查看
# tail /var/log/secure
Mar 20 20:02:59 jenkins02 sshd[28837]: Authentication refused: bad ownership or modes for directory /home/jenkins/.ssh
Mar 20 20:03:00 jenkins02 sshd[28837]: Connection closed by 10.0.0.1 port 41914 [preauth]
从日志可以看出是 /home/jenkins/.ssh/ 目录权限不对
# ll /home/jenkins/.ssh -d
drwxrwxrwx 3 jenkins jenkins 4096 Mar 20 20:04 /home/jenkins/.ssh
权限被人改成 777 了,所以免密登录会失败
修改目录权限为 700,问题解决
# chmod 700 /home/jenkins/.ssh