一、问题描述

hexo cl和hexo g都没有问题,但是在hexo d步骤出现了:

1
2
3
4
ssh: connect to host github.com port 22: Connection timed out  
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed

二、解决方案

参考:关于本地git通过ssh链接github时 time out问题的解决方法_github timeout-CSDN博客)

在C:\Users\YourUserName\ .ssh目录下找到config文件,没有就新建一个
(其中,YourUserName是你的用户名,因人而异)

在windows中,这个config文件没有后缀,即没有指定类型,而在文件管理器中创建文件需要指定类型。有两种办法解决:

  1. 我们可以复制同一目录下,类型仅为“文件”二字的其他文件,然后右键重命名为config
  2. 在平时写代码的IDE下可以直接创建没有指定类型的File(我知道IDEA可以)

右键config文件,选择打开方式,选择记事本,将内建内容修改为如下:

1
2
3
4
5
Host github.com HostName 
ssh.github.com
User git Port 22
PreferredAuthentications publickey
IdentityFile C:\Users\YourUserName\.ssh\id_rsa # 解决问题的关键

与引用的文章不同,我们解决问题的关键是第五行,将IdentityFile后面的文件路径修改为自己电脑下id_rsa的路径就好了

注意:ssh默认连接22端口,如果第三行将端口号修改成了443,应该在博客文件夹主配置文件_config.yaml中在deploy下指定端口,如:

1
2
3
4
5
deploy:  
type: git
repo: git@github.com:andreww1219/andreww1219.github.com.git
branch: master
port: 443 # 这句话指定端口