SSH突然要求输入密码

时间:2014-08-12 06:24:39

标签: ssh

一般问题

我有我的电脑(Mac OSX 10.9.4)和远程服务器(Ubuntu 14.04.1 LTS)。我使用ssh-keygen创建了一个ssh密钥(没有密码),将公钥添加到服务器的.ssh/authorized_keys,并且一切都很好。然后,今天早些时候,ssh开始再次要求我输入密码。

可能导致它的原因

我真的不确定是什么造成的 - 这些是我最好的猜测:

  • 我不得不从远程服务器上的主目录中删除一些文件,因为我不小心在那里复制了一个git存储库(我没有提交任何东西或者其他东西,只是复制了一些东西,然后rm'd他们)。从我的命令历史中可以看出,我没有删除ssh相关文件,只有.git,.gitignore和各种* .sw?文件中剩余的文件。
  • 我在远程服务器上运行ssh-keygen -l -f ~/.ssh/authorized_keys,以查看(我认为)该文件中的密钥的指纹。

相关日志

当我运行ssh -v -i ~/.ssh/mykey_rsa user@serverip时,我明白了:

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /Users/myusername/.ssh/config
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 50: Applying options for *
debug1: Connecting to {ip address} [{ip address}] port 22.
debug1: Connection established.
debug1: identity file .ssh/mykey_rsa type 1
debug1: identity file .ssh/mykey_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version
OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH*
debug1:  Miscellaneous failure (see text)
No credentials cache file found

debug1:  An invalid name was supplied
unknown mech-code 0 for mech 1 2 752 43 14 2

debug1:  Miscellaneous failure (see text)
unknown mech-code 0 for mech 1 3 6 1 5 5 14

debug1:  Miscellaneous failure (see text)
unknown mech-code 2 for mech 1 3 6 1 4 1 311 2 2 10

debug1:  An unsupported mechanism was requested
unknown mech-code 0 for mech 1 3 5 1 5 2 7

debug1:  Miscellaneous failure (see text)
unknown mech-code 0 for mech 1 3 6 1 5 2 5

debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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: Server host key: RSA {fingerprint}
debug1: Host '{ip address}' is known and matches the RSA host key.
debug1: Found key in /Users/myusername/.ssh/known_hosts:16
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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 RSA public key: .ssh/otherkey_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: .ssh/mykey_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
user@serverip's password: 

我发现它在我告诉它使用的那个(mykey_rsa)之前尝试了一个不同的ssh密钥(otherkey_rsa)有点奇怪,但我对ssh解析得不够了解。

同时,远程服务器的/var/log/auth.log有用地说

Aug 12 02:04:19 servername sshd[22147]: error: Could not load host key: /etc/ssh/ssh_host_ed25519_key
Aug 12 02:04:19 servername sshd[22147]: Authentication refused: bad ownership or modes for directory /root

权限

本地/在我的电脑上:

~/                     drwxr-xr-x+ 105 myusername staff 3570 Aug 11 23:14
~/.ssh/                drwx------   13 myusername staff  442 Aug 11 23:14
~/.ssh/mykey_rsa.pub   -rw-r--r--    1 myusername staff  397 Aug  5 20:52
~/.ssh/mykey_rsa       -rw-------    1 myusername staff 1675 Aug  5 20:52

远程/在服务器上:

~/                     drwxr-xr-x    8        501 staff 4096 Aug 12 02:16
~/.ssh/                drwx------    2 remoteuser root  4096 Aug 12 01:49
~/.ssh/authorized_keys -rw-------    1 remoteuser root   794 Aug 12 01:44

我真的很难过,真的很感激帮助!谢谢!

3 个答案:

答案 0 :(得分:6)

正如aecolley指出超级用户,答案就是盯着我。问题具有权限,原因是拥有uid 501的用户拥有我的主目录。你为什么问?因为我(有点意外)使用rsync从我的笔记本电脑复制了一堆文件,rsync似乎使用了我的笔记本电脑的用户ID(501,OS X上的默认值)这份工作。

来自服务器上我主目录的

chown root .修复了问题。

答案 1 :(得分:0)

也许这对某人有用。

我在Ubuntu上遇到了同样的问题:有一天我试图推送到git repo并得到密码提示。在我的情况下,问题是〜/ .ssh / config文件的权限错误(root是文件所有者)。

要解决此问题,我必须更改文件所有者,然后重新登录。

答案 2 :(得分:0)

我在约塞米蒂的这个问题上花了半个小时的时间撕掉我的头发。我的所有权限都是正确的,关键是在正确的位置,配置是正确的等等。

发生了什么事:我使用迁移助手将一些文件从这台机器转移到另一台,这导致交互式用户会话退出但实际上没有重启机器,所以当我记录回来并开始"bannana"它重新连接到一个幸存的会话。显然,这导致它失去了访问Keychain的某种安全权限,Keychain存储了我的密钥,并且它不会重新提示我。只需重新启动tmux即可解决问题!

相关问题