CentOS配置SSH免密码登录后,仍提示输入密码------[接-(准备完全分布式主机的 ssh)]
CentOS配置SSH无密码登录需要3步:
- 生成公钥和私钥
- 导入公钥到认证文件,更改权限
- 测试
1.生成公钥和私钥
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
默认在 ~/.ssh目录生成两个文件:
id_rsa :私钥
id_rsa.pub :公钥
2.导入公钥到认证文件
2.1 导入本机
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
2.2 导入要免密码登录的服务器
首先将认证文件复制到服务器
scp ~/.ssh/authorized_keys xxx@主机名:/home/xxx/.ssh/
一般以上几步就ok了,但我的仍要输入密码,
用root用户登陆查看系统的日志文件:$tail /var/log/secure -n 20
…………
Oct 7 10:26:43 MasterServer sshd[2734]: Authentication refused: bad ownership or modes for file /home/Hadooper/.ssh/authorized_keys
Oct 7 10:26:48 MasterServer sshd[2734]: Accepted password for hadooper from ::1 port 37456 ssh2
Oct 7 10:26:48 MasterServer sshd[2734]: pam_unix(sshd:session): session opened for user hadooper by (uid=0)
Oct 7 10:36:30 MasterServer sshd[2809]: Accepted password for hadooper from 192.168.1.241 port 36257 ssh2
Oct 7 10:36:30 MasterServer sshd[2809]: pam_unix(sshd:session): session opened for user hadooper by (uid=0)
Oct 7 10:38:28 MasterServer sshd[2857]: Authentication refused: bad ownership or modes for directory /home/hadooper/.ssh
…………
提示/home/hadooper/.ssh和 /home/hadooper/.ssh/authorized_keys权限不对,修改如下:
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys
3.测试
ssh host,第一次登录可能需要yes确认,之后就可以直接登录了。