记一次git部署22端口拒绝连接

前言

最近重新弄了下hexo博客,更新了几篇文章,删了一些没大用的东西,在部署时候发现部署不了

提示22端口拒绝连接

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
FATAL {
err: Error: Spawn failed
at ChildProcess.<anonymous> (D:\XXX\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (node:events:390:28)
at ChildProcess.cp.emit (D:\XXX\node_modules\cross-spawn\lib\enoent.js:34:29)
at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) {
code: 128
}
} Something's wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html

解决办法

改用备用的443端口访问,

在C:\Users\XXX\.ssh目录下,config文件写入如下:

1
2
3
Host github.com
Hostname ssh.github.com
Port 443

如果没有config文件,可创建config.txt文件,然后编辑后删除.txt后缀保存为config文件

再次使用ssh -T git@github.com测试是否能连接上,是否继续连接时,回答yes

出现Hi XXX! You’ve successfully authenticated, but GitHub does not provide shell access.说明连接成功了

1
2
3
4
5
6
The authenticity of host '[ssh.github.com]:443 ([20.205.243.160]:443)' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxx.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi XXX! You've successfully authenticated, but GitHub does not provide shell access.

部署后我发现还是访问不了,我看了下仓库是更新的,直接用xxx.github.io也能访问,看了下pages,发现自定义域名这没了,加上后正常访问了

问题排查

为什么会出现这种情况呢?

可能是22端口被防火墙、路由等屏蔽了,也看别网上有换成手机热点连接就正常22端口访问的,也有流量换营运商的也正常访问

还有我猜测最近我访问github长这样,应该就是一类原因

我本地并未手动指定DNS,host记录也没有指定映射

后面发现竟然是运营商的DNS污染!电信和联通是正常的,我的正是移动哈哈哈

解决建议

手动指定DNS或者修改本地host添加映射