博客维护日志 2026-03-02 - Hexo 部署问题修复

今日工作概述

今天解决了困扰已久的 Hexo 部署失败问题。整个过程虽然遇到了一些波折,但最终都顺利解决了。


部署问题修复

问题现象

执行 hexo deploy 时遇到错误:

1
2
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Spawn failed

问题诊断

通过逐步排查,发现了问题根源:

  1. Git 凭据文件缺失:配置的凭据文件 C:/Users/liuzhigui/.my-credentials 不存在
  2. SSH 密钥问题:虽然有 austoin.id_rsa 私钥,但没有对应的公钥文件
  3. GitHub SSH 连接失败:22 端口被防火墙阻止

解决方案

步骤 1:生成新的 SSH 密钥

1
ssh-keygen -t ed25519 -C "liuzhigui_2023@qq.com" -f ~/.ssh/id_ed25519 -N ""

生成了新的 ED25519 密钥对:

  • 私钥:~/.ssh/id_ed25519
  • 公钥:~/.ssh/id_ed25519.pub

步骤 2:添加公钥到 GitHub

将生成的公钥添加到 GitHub Settings → SSH and GPG keys:

1
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDfP3O6tEdZ38+HnO8Js2gkotW2ItOQ2kyTwkjC1BYJU liuzhigui_2023@qq.com

步骤 3:配置 SSH 使用 443 端口

由于 22 端口被阻止,配置使用 GitHub 的 443 端口(HTTPS 端口)绕过防火墙:

编辑 ~/.ssh/config

1
2
3
4
5
6
# GitHub SSH 配置(使用 443 端口绕过防火墙)
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile "C:\Users\liu'zhi'gui\.ssh\id_ed25519"

步骤 4:添加 GitHub 主机密钥

1
ssh-keyscan -p 443 ssh.github.com >> ~/.ssh/known_hosts

步骤 5:测试 SSH 连接

1
2
ssh -T git@github.com
# 输出:Hi Austoin/Austoin.github.io! You've successfully authenticated...

步骤 6:修改 Hexo 配置

_config.yml 中的部署地址从 HTTPS 改为 SSH:

1
2
3
4
5
6
7
8
9
10
11
# 修改前
deploy:
type: git
repo: https://github.com/Austoin/Austoin.github.io.git
branch: main

# 修改后
deploy:
type: git
repo: git@github.com:Austoin/Austoin.github.io.git
branch: main

步骤 7:配置 Git 换行符处理

消除换行符警告:

1
git config --global core.autocrlf true

三、部署验证

完成配置后,执行部署命令:

1
hexo clean && hexo generate && hexo deploy

部署结果:

1
2
3
4
5
6
7
INFO  132 files generated in 4.28 s
INFO Deploying: git
[master 44221ba] Site updated: 2026-03-02 15:10:08
68 files changed, 70 insertions(+), 64 deletions(-)
To github.com:Austoin/Austoin.github.io.git
eaf0c0c..44221ba HEAD -> main
INFO Deploy done: git

✅ 部署成功!博客已更新到 GitHub Pages。


四、技术要点总结

SSH 密钥认证优势

  1. 安全性高:无需在配置文件中存储密码或 Token
  2. 便捷性强:配置一次后无需每次输入密码
  3. 兼容性好:支持多种 Git 托管平台

SSH 443 端口技巧

当 22 端口被防火墙阻止时,可以使用 GitHub 提供的 443 端口:

  • 主机名:ssh.github.com
  • 端口:443
  • 功能完全相同,只是走 HTTPS 端口

Hexo 部署配置

推荐使用 SSH 方式部署:

1
2
3
4
deploy:
type: git
repo: git@github.com:username/username.github.io.git
branch: main

优点:

  • 无需管理 Token
  • 不会过期
  • 更安全

五、遇到的问题与解决

问题 1:SSH 连接超时

现象ssh: connect to host github.com port 22: Connection timed out

原因:22 端口被防火墙或网络阻止

解决:使用 443 端口替代

问题 2:Host key verification failed

现象:首次连接时提示主机密钥验证失败

原因known_hosts 中没有 GitHub 的主机密钥

解决:使用 ssh-keyscan 添加主机密钥

问题 3:换行符警告

现象:大量 LF will be replaced by CRLF 警告

原因:Windows 和 Linux 换行符不同

解决:配置 core.autocrlf true 自动处理


六、后续优化

  1. 定期备份 SSH 密钥:将密钥文件备份到安全位置
  2. 使用 SSH Agent:避免每次都输入密钥密码(如果设置了密码)
  3. 配置多个 SSH 密钥:为不同平台使用不同密钥

总结

今天的工作虽然遇到了一些技术问题,但通过系统的排查和解决,不仅修复了部署问题,还学习到了 SSH 配置的一些技巧。特别是使用 443 端口绕过防火墙的方法,在网络受限的环境下非常实用。

今日成果:

  • ✅ 生成并配置 SSH 密钥
  • ✅ 解决 Hexo 部署失败问题
  • ✅ 成功部署博客更新
  • ✅ 优化 Git 配置

继续加油!💪