使用git上传代码时,原本应该在几秒钟上传成功,但是却异常的慢,,这时突然出现一个错误弹窗(忘记截图了):

提示: “ssh:connect to host github.com port 22: Connection timed out”

再多尝试几次,依然是这样。

后来又尝试直接再文件夹里用git命令行提交:

可惜结果依然是失败。。。

又尝试重启电脑,结果毫无乱用。

最后通过查阅各种资料,得知原因可能是由于电脑的防火墙或者其他网络原因导致ssh连接方式 端口22被封锁。


解决方法一:

参考此篇文章

解决方法二:

  1. 进入~/.ssh下
  2. 创建一个config文件
  3. 编辑文件内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

4.保存退出

5.检查是否成功

1
ssh -T git@github.com

此时可以提交了

其他问题:

当我输入hexo g时,会出现如下错误:

image-20250120095943942

从错误信息中可以看出,问题发生在 Hexo 处理 _posts/git问题.md 文件时,出现了 YAML 格式错误。主要错误是 YAMLException: bad indentation of a mapping entry,这表明该文件的 Front Matter(前置数据块)部分存在缩进或语法问题。此外,还有一个提示 connect to host github.com port 22: Connection timed out,这可能与网络连接有关,但不太可能直接导致 Hexo 生成失败。

解决方法:

我此篇博客的title“Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”注意到,其中是有“”的,这可能导致上传失败。将title改为"“Git问题:解决“ssh:connect to host github.com port 22: Connection timed out”"即可解决此问题,同时后面的那个Connection timed out错误也解决了(昨天晚上折腾了2小时去解决网络问题,没想到问题出在这里,还是以后要注意看报错呀!!!)