首页 > 解决方案 > github ssh 密钥不被接受,得到 ssh 数据包类型 51 (

问题描述

我正在尝试在我的 github 帐户上设置一个 ssh 密钥,但它不断被 github 服务器拒绝。我的客户端是一个基于 Ubuntu 的系统。

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

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

然而,当我尝试 ssh 到 github 时,我的权限被拒绝。所以我增加了客户端 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 客户端所知道的。我不确定这是多大的问题。我的猜测是这只是一个警告。FWIW,它确实报告了 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”(根据 rfc 4250)。

这当然意义重大!但是,它只告诉我们 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).

标签: githubsshssh-keys

解决方案


问题是用户名。对于 GitHub,所有 SSH 操作都通过git用户名进行,并且您仅通过您的密钥来识别。所以你需要做ssh -vvv -T git@github.com.

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


推荐阅读