解决github Connection closed by port 22

最近china的防火墙升级,屏蔽了22端口。GitHub 支持通过 443 端口使用 SSH(因为 443 通常用于 HTTPS 流量,不易被屏蔽)。

问题示例

1
2
3
4
5
test git:(master) git push origin master
Connection closed by 20.205.243.166 port 22
fatal: 无法读取远程仓库。

请确认您有正确的访问权限并且仓库存在。

配置SSH默认使用443端口

1.修改SSH配置文件

1
vim ~/.ssh/config
1
2
3
4
5
#添加以下内容
Host github.com
Hostname ssh.github.com
Port 443
User git

2.设置文件权限

1
chmod 600 ~/.ssh/config

3.测试连接

1
ssh -T git@github.com

可以看到

1
Hi guy! You've successfully authenticated, but GitHub does not provide shell access.

这样就可以重新 git push origin main/master