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

来源:互联网 发布:php 手机回收网站源码 编辑:程序博客网 时间:2024/05/01 22:04

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

具体情况是这样的:

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

ssh-keygen -t rsa -P '' -f id_rsacat id_rsa.pub >> authorized_keysssh localhost

出现下面命令

username@localhost ~ $ ssh localhostThe 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)? yesWarning: Permanently added 'localhost (::1)' (RSA) to the list of known hosts.

username@localhost’s password:

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

chown username: /home/username/.ssh  chown username: /home/username/.ssh/*  chmod 700 /home/username/.ssh  chmod 600 /home/username/.ssh/*  

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

(未完)
之后又出现了如下问题

SSH生成id_rsa, id_rsa.pub后,连接服务器却报:

Agent admitted failure to sign using the key

错误。

解决方法:

在当前用户下执行命令:

ssh-add
将私钥添加进来即可,要在没有登录ssh的情况下使用,即可解决。

0 0
原创粉丝点击