今天在设置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的用户和权限
- chownusername:/home/username/.ssh
- chownusername:/home/username/.ssh/*
- chmod700/home/username/.ssh
- chmod600/home/username/.ssh/*
这样一切就可以直接免密码登录了。