linux下设置了SSH免密码登陆但仍是须要输入密码的解决办法

今天在设置linux的免密码登陆后,仍然须要输入密码,后来找到了缘由,是由于用户没有权限修改.ssh目录下的know_hosts文件致使的。linux

具体状况是这样的:ssh

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

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

#cat id_rsa.pub >> authorized_keysci

#ssh localhostit

出现下面命令
class

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/*  
这样一切就能够直接免密码登陆了。