现象
开启 OpenClash 后执行 git pull,连不上 GitHub 的远程仓库:
git pull
Connection closed by 198.18.0.xx port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
198.18.0.0/15 是 Clash 一类工具用来接管流量的保留网段,出现这个地址说明 SSH 的 22 端口流量被代理接走了,而代理没有把这条连接送到 GitHub。
办法:让 SSH 改走 443 端口
GitHub 提供了一个在 443 端口上跑的 SSH 入口 ssh.github.com,而 443 通常是代理放行的端口,把 SSH 引到这边就能绕开上面的问题。
先测 443 能不能通
ssh -T -p 443 git@ssh.github.com
成功的话会回一段认证通过、但不提供 shell 的提示:
Hi USERNAME! You've successfully authenticated, but GitHub does not
provide shell access.
写 ~/.ssh/config
文件不存在就新建,加上一段,把 github.com 的连接重定向到 443 端口:
Host github.com
Hostname ssh.github.com
Port 443
User git
验证并确认指纹
ssh -T git@github.com
第一次连 [ssh.github.com]:443 会出现主机指纹确认:
The authenticity of host '[ssh.github.com]:443 ([140.82.112.36]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This host key is known by the following other names/addresses:
~/.ssh/known_hosts:32: github.com
Are you sure you want to continue connecting (yes/no/[fingerprint])?
拿这个指纹和 GitHub 官方文档公布的 SSH 密钥指纹对一下,一致再输 yes,以后就不会再问。
参考:https://docs.github.com/zh/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
评论
还没有人留言。