问题现象
开启 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.
解决方案:在 HTTPS 端口使用 SSH 连接
1:测试 443 端口 SSH 连通性
首先确认本地可通过 443 端口连接 GitHub 的 SSH 服务器,执行以下命令测试:
ssh -T -p 443 [email protected]
若测试成功,会输出以下提示(说明 443 端口可正常连接 GitHub SSH 服务):
Hi USERNAME! You've successfully authenticated, but GitHub does not
provide shell access.
2:配置 SSH 强制使用 443 端口
- 打开 SSH 配置文件(若无此文件,直接创建即可):
vim ~/.ssh/config - 在配置文件中添加以下内容(覆盖 GitHub 的 SSH 连接规则):
Host github.com
Hostname ssh.github.com
Port 443
User git
- 保存
3:验证配置并处理已知主机警告
测试 GitHub SSH 连接:
ssh -T [email protected]
确认 SSH 指纹与 GitHub 官方发布的指纹一致(可参考 GitHub 官方文档:GitHub 的 SSH 密钥指纹),确认无误后输入 yes 即可,后续连接将不再出现此警告。
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])?
参考文档:https://docs.github.com/zh/authentication/troubleshooting-ssh/using-ssh-over-the-https-port
评论区