我刚刚在电脑上安装了一块新硬盘,并从备份中恢复了我的 id_rsa 密钥。但是,当我尝试连接到 SSH 时,OSX 要求输入密码。我创建密钥时没有设置密码。无论是否使用密码,我都无法通过公钥连接。我检查了几件事:
权限
SSH 详细日志
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to mydomain.org [xxx.xxx.xxx.xxx] port 22.
debug1: Connection established.
debug1: identity file /Users/jessebunch/.ssh/id_rsa type 1
debug1: identity file /Users/jessebunch/.ssh/id_rsa-cert type -1
debug1: identity file /Users/jessebunch/.ssh/id_dsa type -1
debug1: identity file /Users/jessebunch/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
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 '[mydomain.org]:22' is known and matches the RSA host key.
debug1: Found key in /Users/jessebunch/.ssh/known_hosts:1
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,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/jessebunch/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: Trying private key: /Users/jessebunch/.ssh/id_dsa
debug1: Next authentication method: password
有任何想法吗?
答案1
快速教程关于 RSA 密钥认证如何工作,我找到了答案:
是的。看来我不明白公钥/私钥是如何工作的。我没有备份私钥,只备份了公钥。我试图将公钥恢复到我的 id_rsa 文件中,而我应该恢复私钥。因此,我完蛋了。
学到了什么教训?备份 id_rsa 和 id_rsa.pub 密钥。不是仅 id_rsa.pub 密钥。
答案2
只要我知道,服务器端就不必拥有您的私钥。这是 RSA 身份验证或更一般的非对称密钥身份验证的要点。备份两个密钥是一种很好的做法,但请注意,一旦私钥被泄露,整个非对称身份验证就会被泄露。