linux下设置了SSH免密码登录但还是需要输入密码的解决办法

今天在设置linux的免密码登录后,仍然需要输入密码,后来找到了原因,是因为用户没有权限修改.ssh目录下的know_hosts文件导致的。

具体情况是这样的:

在/home/username/.ssh输入以下命令后:

#ssh-keygen -t rsa -P '' -f id_rsa

#cat id_rsa.pub >> authorized_keys

#ssh localhost

出现下面命令

username@localhost ~ $ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 6e:6b:0f:2a:b8:91:3f:c8:f0:39:e4:df:b4:d8:16:6b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost (::1)' (RSA) to the list of known hosts.
username@localhost's password:  


仍然让我输入密码,这时应该修改一下.ssh的用户和权限

  1. chown username: /home/username/.ssh  
  2. chown username: /home/username/.ssh/*  
  3. chmod 700 /home/username/.ssh  
  4. chmod 600 /home/username/.ssh/*  


这样一切就可以直接免密码登录了。

 

http://blog.csdn.net/shiqidide/article/details/7582572

posted @ 2018-01-24 10:20  追忆丶年华  阅读(1691)  评论(0编辑  收藏  举报