起因:

在使用hexo的hexo deploy时报错,显示Connection closed by 20.205.243.166 port 22,
最初以为是hexo配置的问题,后来单独测试了github ssh连接

尝试使用ssh clone自己的仓库

报错情况:

1
2
3
4
5
6
7
8
➜ spencer@spencerarch  ~   git clone git@github.com:ispencerlee/ispencerlee.github.io.git

Cloning into 'ispencerlee.github.io'...
Connection closed by 20.205.243.166 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

ssh连接github报错

测试ssh链接是否正常

正常情况:

1
2
➜ spencer@spencerarch  ~  ssh -T git@github.com
Hi ispencerlee! You've successfully authenticated, but GitHub does not provide shell access.

会显示你的github用户名,说明连接正常

报错情况:

1
2
➜ spencer@spencerarch  ~  ssh -T git@github.com
Connection closed by 20.205.243.166 port 22

方法:

编辑ssh的config文件

1
$ vim .ssh/config

添加如下内容:
1
2
3
Host github.com
HostName ssh.github.com
Port 443

原因

防火墙有时会拒绝通过ssh的22端口连接, 可以使用https的443端口来连接,这是https的默认开放端口

参考资料:
https://github.com/orgs/community/discussions/54558
https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port