【问题标题】:Github not recognizing ssh keyGithub 无法识别 ssh 密钥
【发布时间】:2022-01-14 20:32:43
【问题描述】:

我在 github 上使用 ssh 密钥已经有一段时间了。突然我无法推动,我得到了Permission denied (publickey) error. 到目前为止,这是我尝试过的:

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

到目前为止,没有任何帮助。这是我最后的手段。我将不胜感激任何和所有的建议。这是我的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 帐户时遇到了同样的问题。同一台电脑。

【问题讨论】:

  • 希望这个链接能帮助你克服这个问题。 stackoverflow.com/questions/9960897/…
  • SSH 告诉你​​它找不到对应于id_rsa:debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1 debug1: key_load_public: No such file or directory 的公钥。此外,在提供 id_rsa 密钥后,ssh 服务器没有响应“身份验证成功”。您是否绝对、肯定、100% 确定您已将正确的相应公钥上传到 github?
  • 正如@kalatabe 所说:debug1: identity file /home/MY_USER_NAME/.ssh/id_rsa type 1 表示 ssh 已找到 .ssh/id_rsa。但debug1: key_load_public: No such file or directory 表示 ssh 没有 找到 .ssh/id_rsa.pub - 与此私钥一起使用的公钥。目前尚不清楚为什么没有找到它,因为 ssh-keygen 会成对生成它们,但我怀疑代理设置有问题。
  • @kalatabe “key_load_public”错误是指列表中的下一个键,而不是前一个键。 ssh 找到 id_rsa,但没有找到 id_rsa-cert 等
  • @kalatabe 我仔细检查了一下,公钥就在那里。另外,我有点新手,所以如果我错了,请纠正我,但我的印象是你不需要公钥来进行身份验证。只要您的服务器有公钥(github 有),它就是用于身份验证的私钥。

标签: git github ssh ssh-keys


【解决方案1】:

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

【讨论】:

  • 删除known_hosts 是一个潜在的安全风险,除非您完全了解其影响,否则应不惜一切代价避免。此外,日志包含Host 'github.com' is known and matches the RSA host key.,因此更改主机密钥不会成为这里的问题,并且操纵known_hosts 不太可能有帮助。
猜你喜欢
  • 2012-03-22
  • 2013-08-12
  • 1970-01-01
  • 2018-12-15
  • 2013-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多