GitHub无法识别SSH密钥

taor4pac  于 2022-09-21  发布在  Git
关注(0)|答案(4)|浏览(228)

我在GitHub中使用SSH密钥已经有一段时间了。突然我不能推了,我得到了Permission denied (publickey) error.,这是我到目前为止尝试过的:

  • 已检查ssh密钥是否位于正确的目录(~/.ssh)
  • 尝试将我的公钥重新上传到GitHub(我收到密钥已经存在的消息)
  • 仔细检查系统上ssh-add -l -E sha256的输出是否与我在GitHub帐户上的ssh设置中的字符串一致
  • 已按照GitHub文档的“故障排除ssh”部分中的所有步骤进行操作。(一切似乎都像古驰)
  • 我的头撞墙了一个小时

到目前为止,任何事情都没有帮助。这是我最后的手段。如有任何建议,我将不胜感激。以下是我的ssh -vT git@github.com的输出

OpenSSH_7.2p2 Ubuntu-4ubuntu2.10, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/MY_USER_NAME/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [140.82.114.3] port 22.
debug1: Connection established.
debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/MY_USER_NAME/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10
debug1: Remote protocol version 2.0, remote software version babeld-fb957b4d
debug1: no match: babeld-fb957b4d
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: rsa-sha2-512
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/MY_USER_NAME/.ssh/known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/MY_USER_NAME/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 279
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_dsa
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_ecdsa
debug1: Trying private key: /home/MY_USER_NAME/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

**更新:**我在另一个GitHub帐户上遇到了相同的问题,该帐户具有不同的密钥集。同一台电脑。

2skhul33

2skhul331#

所以,我终于想通了。事实证明,我的计算机只是不喜欢我有多个ssh密钥的事实(可能是因为其中一个是密码保护的,其他的不是?)将所有ssh键从~/.ssh目录移出并重新启动计算机解决了我的问题。我之前尝试删除了所有ssh密钥,但显然也需要重新启动。

2nc8po8w

2nc8po8w2#

请注意,如果您有一个旧的DSA密钥,您将看到“Server Accept Key:”,但最终仍将失败。GH正在逐步淘汰DSA密钥,因此它可能已经“被接受”,但不允许继续进行。

bvjxkvbb

bvjxkvbb3#

我的回答可能无济于事,也可能听起来很愚蠢。但在我的情况下,我只是删除know_hosts文件并再次拉/推,然后一切都按预期工作。

5vf7fwbs

5vf7fwbs4#

一个可能的根本原因是HostHostName无法在SSH连接中拦截您的目标FQDN或IP地址。尝试修改HostHostName以与目标服务器匹配。

还要为git命令启用调试模式。

git -c core.sshCommand="ssh -vvv" clone

相关问题