解决 GitHub Connect: kex_exchange_identification: Connection closed by remote host
背景
想要克隆项目/推送代码到 GitHub 老实错误,检查发现:
➜ ~ ssh -vvv git@github.com
OpenSSH_8.1p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/chuwen/.ssh/config
debug1: /Users/chuwen/.ssh/config line 1: Applying options for *
debug1: /Users/chuwen/.ssh/config line 6: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Executing proxy command: exec nc -v -x 127.0.0.1:7890 github.com 443
debug1: identity file /Users/chuwen/.ssh/id_rsa type 0
debug1: identity file /Users/chuwen/.ssh/id_rsa-cert type -1
debug1: identity file /Users/chuwen/.ssh/id_dsa type -1
debug1: identity file /Users/chuwen/.ssh/id_dsa-cert type -1
debug1: identity file /Users/chuwen/.ssh/id_ecdsa type -1
debug1: identity file /Users/chuwen/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/chuwen/.ssh/id_ed25519 type -1
debug1: identity file /Users/chuwen/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/chuwen/.ssh/id_xmss type -1
debug1: identity file /Users/chuwen/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.1
Connection to github.com port 443 [tcp/https] succeeded!
kex_exchange_identification: Connection closed by remote host
解决方案
最后找到一篇文章解决了这个问题。
只需要在 ~/.ssh/config
配置以下项目即可
Host github.com
HostName ssh.github.com
User git
Port 443
如果想要配置代理可以这样:
Host github.com
HostName ssh.github.com
User git
Port 443
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
# 走 socks5 代理(如 Shadowsocks)
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
最终解决了问题
➜ ~ ssh -T git@github.com
Connection to ssh.github.com port 443 [tcp/https] succeeded!
Hi PrintNow/react-i18next-base-usage! You've successfully authenticated, but GitHub does not provide shell access