SSH要求输入密码

我已经完成以下步骤:
  • 安装了服务器
  • 使用 -P "" 生成了公钥/私钥
  • 将 id_rsa.pub 复制到 authorized_keys
  • 通过 ssh localhost 连接,并回答 "yes",并将其复制到 known_hosts
  • 尝试通过 ssh localhost 连接,仍然要求输入密码
输出结果:
hduser@hduser1-desktop:~$ ssh -v localhost
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/hduser/.ssh/identity type -1
debug1: identity file /home/hduser/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/hduser/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-
3ubuntu7
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/hduser/.ssh/known_hosts:3
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/hduser/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/hduser/.ssh/identity
debug1: Trying private key: /home/hduser/.ssh/id_dsa
debug1: Next authentication method: password

有什么建议吗?
3个回答

尝试使用ssh-copy-id命令。可能会遇到权限问题。该程序会设置正确的权限。

这是本地主机,所以它不应该解决这些问题吗? - user1435470
问题已解决:chmod g-w homedirectory。在我看来,这是一个奇怪的问题或者bug。谢谢。 - user1435470
1@用户1435470:根本不是bug。这是sshd的安全预防措施,只有您(和root)才能修改允许的密钥文件。顺便说一下,~/.ssh上的权限也很重要。 - 0xC0000022L
将家目录和.ssh文件夹的权限设置为750并不能解决我的问题。我仍然无法"ssh localhost"而不需要输入密码。我真的很希望能做到这一点,这样我就可以使用一个Fabric脚本来配置服务器以搭建我的本地开发/测试环境。 - Jonathan Hartley
答案对我没有帮助:http://askubuntu.com/questions/628188/ssh-keeps-asking-for-a-password - gsamaras

检查文件/home/hduser/.ssh/authorized_keys的权限和所有权。
它应该是-rw------- hduser hduser。
如果不是,您可以通过以下方式修复:
chown hduser:hduser ~hduser/.ssh/authorized_keys
chmod 0600 ~hduser/.ssh/authorized_keys

然后尝试使用本地主机连接
ssh -i /home/hduser/.ssh/id_rsa hduser@localhost

如果还是不起作用,以你喜欢的方式检查一下最近的身份验证日志。
sudo tail /var/log/auth.log
sudo cat /var/log/auth.log
sudo less /var/log/auth.log
sudo grep "Authentication refused" /var/log/auth.log
...

找到类似的东西,然后谷歌一下你收到的错误信息。
Jan 21 09:03:11 hduser sshd[29543]: Authentication refused: ...

确保你的 /etc/ssh/sshd_config 文件中有以下设置: PubkeyAuthentication yes ChallengeResponseAuthentication no UsePAM yes AllowUsers YOUR_USER_NAME

这个没有帮到我:http://askubuntu.com/questions/628188/ssh-keeps-asking-for-a-password - gsamaras