首页 > 解决方案 > Git push over ssh 在 Windows 上失败,出现“远程端意外挂断”错误

问题描述

我希望有人可以帮助我,因为我已经为此奋斗了好几天,并且很难过。我在运行 Windows 10 的全新笔记本电脑上设置了标准 git 客户端(来自 git-scm.com),并且正在研究托管在 Github.com 上的存储库。

最初,由于本地 Windows OpenSSH 客户端与 git 附带的捆绑 SSH 客户端发生冲突,我在 SSH 配置中遇到了一些冲突。所以身份验证失败。这个,我已经设法通过根据Adam Ralph 的建议sshCommand明确设置全局配置值来解决。这让我克服了身份验证问题,我能够很好地从 GitHub 克隆、获取和拉取。但是,当我尝试推送时,我没有遇到以下错误。

Counting objects: 15, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (15/15), 3.20 KiB | 252.00 KiB/s, done.
Total 15 (delta 1), reused 0 (delta 0)
Connection to github.com closed by remote host.
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

我一直在搜索 google 和 stackoverflow,并尝试了我能找到的所有解决方案:

在这一点上,我可以通过切换到 HTTPS 远程连接来解除阻止实际工作的能力,但是在我使用 git 的几年中,我从未遇到过使用 SSH 的此类问题。有没有人遇到过这样的事情?有什么明显的我失踪了。

OpenSSH_7.7p1, OpenSSL 1.0.2o  27 Mar 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "github.com" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: Connection established.
debug1: identity file /c/Users/John/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/John/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version babeld-f43b814b
debug1: no match: babeld-f43b814b
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
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-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: 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,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc,aes256-cbc,aes192-cbc
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@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
debug2: host key algorithms: ssh-dss,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc
debug2: MACs ctos: hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib,zlib@openssh.com
debug2: compression stoc: none,zlib,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ssh-rsa
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 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/John/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug2: key: /c/Users/John/.ssh/id_rsa (0x600061250)
debug2: key: /c/Users/John/.ssh/id_dsa (0x0)
debug2: key: /c/Users/John/.ssh/id_ecdsa (0x0)
debug2: key: /c/Users/John/.ssh/id_ed25519 (0x0)
debug2: key: /c/Users/John/.ssh/id_xmss (0x0)
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:0imySt9BYYbsr5CLqXP5JRHwHNCXAYuotf8/6WGE4sU /c/Users/John/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp SHA256:0imySt9BYYbsr5CLqXP5JRHwHNCXAYuotf8/6WGE4sU
debug1: Authentication succeeded (publickey).
Authenticated to github.com ([192.30.253.112]:22).
debug2: fd 4 setting O_NONBLOCK
debug2: fd 5 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug2: channel 0: send open
debug1: Entering interactive session.
debug1: pledge: network
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug2: client_session2_setup: id 0
debug1: Sending command: git-receive-pack 'john-shaskin/polly-notes-reader.git'
debug2: channel 0: request exec confirm 1
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 32000 rmax 35000
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
Counting objects: 15, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (11/11), done.
Writing objects:  13% (2/15)   1248163Writing objects:   6% (1/15)
Writing objects: 100% (15/15), 3.20debug2: channel 0: read<=0 rfd 4 len 0 KiB | 192.00 KiB/s, done.
Total 15 (delta 1), reused 0 (delta 0)
debug2: channel 0: read failed
debug2: channel 0: close_read
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug2: channel 0: input drain -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
pectedlychannel 0: output drain -> closedfatal: The remote end hung up unexpectedly
fatal: The remote end hung up unex
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed by remote host.
Transferred: sent 6880, received 2096 bytes, in 0.5 seconds
Bytes per second: sent 13415.2, received 4087.0
debug1: Exit status -1

标签: gitgithubssh

解决方案


根据 Adam Ralph 的建议,我设法通过显式设置全局 sshCommand 配置值来解决这个问题。

是,但不是:首先尝试在 CMD 会话中使用 Git,在该会话中放置了一个简化的 PATH,其中 Git 捆绑的 openSSH 将首先出现并使用(OpenSSH_8.2p1,OpenSSL 1.1.1d 2019 年 9 月 10 日)来自 Windows 的旧版本

set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

git config --gobal --unset core.sshCommand
cd C:\path\to\repo
git config --local --unset core.sshCommand

然后在该 CMD 会话中重试,以测试 SSH 问题是否仍然存在。


推荐阅读