今天突然就发现hexo -d执行出错,看输出是ssh认证出问题了。本文记录了修复过程。

出错提示

1
2
3
4
5
6
7
8
9
10
11
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
at ChildProcess.<anonymous> (D:\hexo\blog\node_modules\hexo-deployer-git\node_modules\hexo-util\lib\spawn.js:51:21)
at ChildProcess.emit (node:events:518:28)
at cp.emit (D:\hexo\blog\node_modules\cross-spawn\lib\enoent.js:34:29)
at ChildProcess._handle.onexit (node:internal/child_process:293:12)

问题出在ssh认证上。

修复过程(windows 10平台)

  • 重新生成ssh key
    cmd命令行提示下执行:
    ssh-keygen -t rsa -b 4096 -C "email"
    email为github帐号。会在~/.ssh/目录生成id_rsa,id_rsa.pub文件。

  • ssh key保存到github
    登录github,点右上角头像,settings,左侧菜单选择 SSH and GPG keys,点击绿色按钮 New SSH key,用文本编辑器打开id_rsa.pub,把内容粘贴到key里面,点击 Add SSH key。

  • config文件
    ~/.ssh/目录下建立config文件,内容为:

    1
    2
    3
    4
    5
    Host github.com
    Hostname ssh.github.com
    User git
    Port 443
    IdentityFile ~/.ssh/id_rsa

测试

cmd命令行提示下执行:
ssh -T git@github.com
输出为:

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

认证成功。
再执行hexo -d就没有错误提示了。


时间能磨灭一切,之前会的,后面会忘记,记录下来,再出现同样的问题就可以照做了。