centos配置ssh免密码登录后,仍提示输入密码

配置SSH无密码登录需要3步:

    1.生成公钥和私钥

    2.导入公钥到认证文件,更改权限

    3.测试

 

1.生成公钥和私钥

Shell代码  
  1. ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa

  
   默认在 ~/.ssh目录生成两个文件:
    id_rsa      :私钥
    id_rsa.pub  :公钥

2.导入公钥到认证文件

    2.1 导入本机

Shell代码  
  1. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys  


 

    2.2 导入要免密码登录的服务器

        首先将认证文件复制到服务器

Shell代码  
  1. 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权限不对,修改如下:      

Shell代码  
  1. chmod 700 ~/.ssh
  2. chmod 600 ~/.ssh/authorized_keys  

   

3.测试

    ssh host,第一次登录可能需要yes确认,之后就可以直接登录了。

 

转自: http://blog.csdn.net/hwwn2009/article/details/39852457

posted @ 2016-01-22 15:43  圆旭  阅读(1135)  评论(0编辑  收藏  举报