SSH突然询问密码 一般问题
我有我的电脑(MacOSX10.9.4)和远程服务器(Ubuntu14.04.1LTS)。我使用SSH突然询问密码 一般问题,ssh,Ssh,我有我的电脑(MacOSX10.9.4)和远程服务器(Ubuntu14.04.1LTS)。我使用ssh-keygen创建了一个ssh密钥(没有密码),将公钥添加到服务器的.ssh/authorized_-keys,一切都很好。然后,今天早些时候,ssh又开始向我询问密码 是什么引起的 我真的不确定是什么原因导致了这一点——以下是我最好的猜测: 当我不小心复制了一个git存储库时,我不得不从远程服务器的主目录中删除一些文件(我没有提交或从那里做任何事情,只是复制了一些东西,然后rm'd了它们)。
ssh-keygen
创建了一个ssh密钥(没有密码),将公钥添加到服务器的.ssh/authorized_-keys
,一切都很好。然后,今天早些时候,ssh
又开始向我询问密码
是什么引起的
我真的不确定是什么原因导致了这一点——以下是我最好的猜测:
- 当我不小心复制了一个git存储库时,我不得不从远程服务器的主目录中删除一些文件(我没有提交或从那里做任何事情,只是复制了一些东西,然后
'd了它们)。从我的命令历史记录中可以看出,没有我删除的ssh相关文件,只有.git、.gitignore和各种*.sw?从vim遗留下来的文件rm
- 我在远程服务器上运行了
,以查看(我认为)该文件中密钥的指纹ssh-keygen-l-f~/.ssh/authorized_keys
ssh-v-I~/.ssh/mykey\u 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:
权限
本地/在我的计算机上:
~/ 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
正如《超级用户》上指出的,答案就在我面前。问题在于权限,原因是uid为501的用户拥有我的主目录。为什么,你问?因为我(有点意外地)使用了rsync
从我的笔记本电脑复制了一堆文件,而且rsync
似乎使用了我笔记本电脑的用户id(501,OS X上的默认值)来完成作业
chown root。
从服务器上的“我的主目录”修复了该问题。也许它对某些人有用
我在Ubuntu上也遇到了同样的问题:有一天,我试图推到git repo,但收到了密码提示。在我的例子中,问题在于~/.ssh/config文件的权限错误(root是文件所有者)
为了解决这个问题,我必须更改文件所有者,然后重新登录。我在优胜美地上花了半个小时来解决这个问题。我所有的权限都正确,密钥在正确的位置,配置正确,等等
发生的情况是:我使用迁移助手将一些文件从这台机器传输到另一台机器,这导致交互式用户会话注销,但实际上没有重新启动机器,因此当我重新登录并启动
tmux
时,它会重新连接到一个幸存的会话。显然,这导致它失去了某种访问Keychain的安全权限,Keychain存储着我的密钥密码,它不会再提示我。只需重新启动tmux就解决了这个问题 如果你在superuser或askubuntu上发布这个问题,你可能会得到很好的回答。谢谢你的回答!我也提出了同样的问题。祝你好运!
~/ 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