GitHub SSH密钥未被接受,收到SSH数据包类型51。

6

我正在尝试在我的 Github 账户上设置 SSH 密钥,但它一直被 Github 服务器拒绝。我的客户端是基于 Ubuntu 的系统。

在 Ubuntu 上,我创建了一个公钥和私钥,存储在 ~/.ssh/id_rsa 和 ~/.ssh/id_rsa.pub 中。对于 ~/.ssh 的权限是 700,对于 id_rsa 的权限是 600,对于 id_rsa.pub 的权限是 644。

当我使用 ssh-keygen 在 Ubuntu 上创建密钥时,ssh-keygen 计算并显示的 sha256 指纹与我在 github 账户中(设置 > 帐户设置 > SSH 和 GPG 密钥)粘贴和保存该密钥后显示的指纹完全匹配。因此,我确定我在 github 中存储的公钥已经正确地粘贴并存储在我的 github 账户中。

然而,当我尝试 ssh 连接到 github 时,我得到了"permission denied"的错误。因此,我将客户端 ssh 应用程序的日志级别增加,并将输出粘贴在下面。

我执行的命令是...

ssh -vvv -T zzzzz60@github.com

浏览调试输出,我看到两个线索...

debug1: Remote protocol version 2.0, remote software version babeld-0843ac0d
debug1: no match: babeld-0843ac0d

这个提示好像在告诉我GitHub上的ssh守护程序不是我的Ubuntu ssh客户端所知道的。我不确定这有多大问题。 我的猜测是这只是一个警告。 顺便说一下,它报告了ssh协议2.0 - 这与我的Ubuntu客户端使用的协议版本相同。

一个更重要的日志条目是这个...

debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51

...数据包类型“51”被定义为SSH_MSG_USERAUTH_FAILURE(根据IANA SSH List)。

这当然很重要!但是,它只告诉我们github由于某种原因不喜欢我们的密钥。它并没有解释 为什么 它不喜欢我们的密钥。

我一直无法进一步进行。我在这个点上遇到了障碍。我无法理解为什么github会拒绝这个密钥。其指纹与ssh-keygen显示的值完全匹配。

所以这就是我的情况。我在这里看到了类似的问题...但没有解决方案。我希望通过提供调试输出,有人能够有所启发。

以下是完整的调试输出...

% ssh -vvvT zzzzz60@github.com
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to github.com [140.82.113.3] port 22.
debug1: Connection established.
debug1: identity file /home/zzzzz60/.ssh/id_rsa type 0
debug1: identity file /home/zzzzz60/.ssh/id_rsa-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_dsa type -1
debug1: identity file /home/zzzzz60/.ssh/id_dsa-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_ecdsa type -1
debug1: identity file /home/zzzzz60/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/zzzzz60/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_ed25519 type -1
debug1: identity file /home/zzzzz60/.ssh/id_ed25519-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_ed25519_sk type -1
debug1: identity file /home/zzzzz60/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/zzzzz60/.ssh/id_xmss type -1
debug1: identity file /home/zzzzz60/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
debug1: Remote protocol version 2.0, remote software version babeld-0843ac0d
debug1: no match: babeld-0843ac0d
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to github.com:22 as 'zzzzz60'
debug3: hostkeys_foreach: reading file "/home/zzzzz60/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/zzzzz60/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from github.com
debug3: order_hostkeyalgs: prefer hostkeyalgs: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c
debug2: host key algorithms: rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: MACs ctos: hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-sha1-etm@openssh.com,hmac-sha1
debug2: MACs stoc: hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,hmac-sha1-etm@openssh.com,hmac-sha1
debug2: compression ctos: none
debug2: compression stoc: none
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
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
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ssh-rsa SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8
debug3: hostkeys_foreach: reading file "/home/zzzzz60/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/zzzzz60/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from github.com
debug3: hostkeys_foreach: reading file "/home/zzzzz60/.ssh/known_hosts"
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/zzzzz60/.ssh/known_hosts:4
Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts.
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/zzzzz60/.ssh/id_rsa RSA SHA256:zj5+CcvII4ZfOQhehs+eVrAI6bO19QBOYUKpnJteanM agent
debug1: Will attempt key: /home/zzzzz60/.ssh/id_dsa 
debug1: Will attempt key: /home/zzzzz60/.ssh/id_ecdsa 
debug1: Will attempt key: /home/zzzzz60/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/zzzzz60/.ssh/id_ed25519 
debug1: Will attempt key: /home/zzzzz60/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/zzzzz60/.ssh/id_xmss 
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
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>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/zzzzz60/.ssh/id_rsa RSA SHA256:zj5+CcvII4ZfOQhehs+eVrAI6bO19QBOYUKpnJteanM agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/zzzzz60/.ssh/id_dsa
debug3: no such identity: /home/zzzzz60/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/zzzzz60/.ssh/id_ecdsa
debug3: no such identity: /home/zzzzz60/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/zzzzz60/.ssh/id_ecdsa_sk
debug3: no such identity: /home/zzzzz60/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /home/zzzzz60/.ssh/id_ed25519
debug3: no such identity: /home/zzzzz60/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /home/zzzzz60/.ssh/id_ed25519_sk
debug3: no such identity: /home/zzzzz60/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /home/zzzzz60/.ssh/id_xmss
debug3: no such identity: /home/zzzzz60/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
zzzzz60@github.com: Permission denied (publickey).

尝试使用RSA加密算法创建密钥。ssh-keygen -t rsa - Ravi Kumar CH
1
密钥已使用RSA创建,如日志消息“Offering public key: /home/zzzzz60/.ssh/id_rsa RSA SHA256:z...”中所确认的那样。 - Robert Byers
1个回答

10

问题出在用户名上。对于GitHub来说,所有SSH操作都是使用git用户名进行的,你只需要用密钥来标识自己。所以你需要执行ssh -vvv -T git@github.com

尽管OpenSSH并不特别了解GitHub上的babeld SSH服务,但依然应该可以正常工作。OpenSSH知道一些特殊的SSH服务器,以便为有问题的行为(例如在某些旧版OpenSSH版本中不兼容的实现curve25519-sha256@libssh.org)应用解决方法,但babeld没有这些问题,这意味着它应该能够正常工作。


太神奇了!我怎么不知道这个?显然,我阅读了一些,但并非全部,关于ssh密钥的github文档。为自己辩护,这似乎是github应该明确说明的事情,在我的经验中,这并不明显。对于那些有使用命令行(带有密钥交换)ssh经验的用户来说,这可能是一个容易犯的错误!这些人,包括我在内,会认为“当然,ssh命令行上的用户名应该是远程系统上的用户名”。实际上,他们甚至不会想到这一点。他们只会知道这就是你用ssh做的事情! - ePhrygian
1
首先在 Stack Overflow 上找到了它,然后是 GitHub 文档 https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey#always-use-the-git-user - Weekend

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接