|
| 1 | +# Connection closed by UNKNOWN port 65535 |
| 2 | + |
| 3 | +git fetch 或者 git push 时看到这个错误。 |
| 4 | + |
| 5 | +## 排查思路 |
| 6 | + |
| 7 | +`ssh -vvv -T [email protected]` 查看与 github.com 的 ssh 链接过程具体有什么问题。 |
| 8 | + |
| 9 | +比如我的案例是: |
| 10 | + |
| 11 | +```sh |
| 12 | +debug3: channel_clear_timeouts: clearing |
| 13 | +debug1: Executing proxy command: exec nc -x 127.0.0.1:7890 github.com 22 |
| 14 | +debug1: identity file /Users/adoyle/.ssh/id_rsa type 0 |
| 15 | +debug1: identity file /Users/adoyle/.ssh/id_rsa-cert type -1 |
| 16 | +debug1: identity file /Users/adoyle/.ssh/id_ecdsa type -1 |
| 17 | +debug1: identity file /Users/adoyle/.ssh/id_ecdsa-cert type -1 |
| 18 | +debug1: identity file /Users/adoyle/.ssh/id_ecdsa_sk type -1 |
| 19 | +debug1: identity file /Users/adoyle/.ssh/id_ecdsa_sk-cert type -1 |
| 20 | +debug1: identity file /Users/adoyle/.ssh/id_ed25519 type 3 |
| 21 | +debug1: identity file /Users/adoyle/.ssh/id_ed25519-cert type -1 |
| 22 | +debug1: identity file /Users/adoyle/.ssh/id_ed25519_sk type -1 |
| 23 | +debug1: identity file /Users/adoyle/.ssh/id_ed25519_sk-cert type -1 |
| 24 | +debug1: identity file /Users/adoyle/.ssh/id_xmss type -1 |
| 25 | +debug1: identity file /Users/adoyle/.ssh/id_xmss-cert type -1 |
| 26 | +debug1: identity file /Users/adoyle/.ssh/id_dsa type -1 |
| 27 | +debug1: identity file /Users/adoyle/.ssh/id_dsa-cert type -1 |
| 28 | +debug1: Local version string SSH-2.0-OpenSSH_9.7 |
| 29 | + |
| 30 | +kex_exchange_identification: Connection closed by remote host |
| 31 | +Connection closed by UNKNOWN port 65535 |
| 32 | +``` |
| 33 | + |
| 34 | +`debug1: Executing proxy command: exec nc -x 127.0.0.1:7890 github.com 22` 表示我的 ssh 走了代理。 |
| 35 | + |
| 36 | +`kex_exchange_identification: Connection closed by remote host` 说明问题发生在 [kex_exchange_identification](https://github.com/openssh/openssh-portable/blob/aee54878255d71bf93aa6e91bbd4eb1825c0d1b9/kex.c#L1237) |
| 37 | + |
| 38 | +目测是 GFW 或者网络代理商的缘故,ssh 传输被中断了。 |
| 39 | + |
| 40 | +## 解决方法 |
| 41 | + |
| 42 | +默认 ssh 用的端口是 22。可以采用 [SSH over the HTTPS port](https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port) 的方式,用 HTTPS 端口传输 SSH 协议。 |
| 43 | + |
| 44 | +修改 ~/.ssh/config,增加这一段: |
| 45 | + |
| 46 | +``` |
| 47 | +Host github.com |
| 48 | +Hostname ssh.github.com |
| 49 | +Port 443 |
| 50 | +User git |
| 51 | +``` |
0 commit comments