测试 GitHub SSH 连接 - 错误:权限被拒绝(公钥),如何解决?

时间:2021-02-06 19:02:15

标签: git github ssh git-bash

从生成新密钥到将其添加到我的 GitHub 帐户,我已按照 the GitHub Docs instructions 创建并向信件添加 SSH 密钥。

我正在使用 Git Bash 在 Win10 上执行此操作。我已成功生成 RSA 密钥对,已将其添加到 ssh-agent,我已将公钥复制粘贴到我的 GitHub 帐户中,没有任何额外的空格等。

当我到达“测试您的 SSH 连接”阶段时,命令 ssh -T git@github.com 返回 git@github.com: Permission denied (publickey).

我已通读 this page 上的所有故障排除建议,但这些修复程序似乎都无法解决问题。

命令 ssh -i ~/.ssh/id_rsa -vT git@github.com 的输出如下:

OpenSSH_8.4p1, OpenSSL 1.1.1i  8 Dec 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
debug1: identity file /c/Users/USER/.ssh/id_rsa type 0
debug1: identity file /c/Users/USER/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.4
debug1: Remote protocol version 2.0, remote software version babeld-c34a939f
debug1: no match: babeld-c34a939f
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
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 /c/Users/USER/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /c/Users/USER/.ssh/id_rsa RSA SHA256:sfCBsdTYd4G3HCltcpNdV68RksreyBB8vruHjzLHkxM explicit agent
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,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,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 public key: /c/Users/USER/.ssh/id_rsa RSA SHA256:sfCBsdTYd4G3HCltcpNdV68RksreyBB8vruHjzLHkxM explicit agent
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

-i 命令中 ssh 之后的路径替换为 ~/.ssh/id_rsa.pub 会产生相同的结果。

有人可以帮我追踪这里出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

已解决 - 我正在按照常规 GitHub.com SSH 连接的说明操作,同时尝试连接到 GitHub 企业服务器。

使用正确的命令进行测试 - ssh -T git@github.[ENTERPRISE ADDRESS] 按预期提供连接。

作为参考,我已经被提醒在GitHub docs的右上方的下拉列表中,您可以选择文章版本;适用于 GitHub.com、GitHub AE 或 Enterprise Server 版本。