Hexo连接失败和中文标签乱码

Hexo 部署报错分析及解决:SSH 连接失败和中文标签乱码

在用 Hexo 部署博客时,有时候会遇到如下报错:

SQL
1
2
3
4
5
6
7
8
9
10
textcreate mode 100644 "tags/\350\275\257\350\267\257\347\224\261/index.html"
create mode 100644 "tags/\351\243\236\347\211\233OS/index.html"
create mode 100644 xml/local-search.xml
Connection closed by ::ffff:0:c612:35 port 22
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

这个报错主要分为两个部分:中文文件名乱码SSH 推送失败


1️⃣ 中文标签文件名乱码

报错中的类似:

APACHE
1
2
texttags/\350\275\257\350\267\257\347\224\261/index.html
tags/\351\243\236\347\211\233OS/index.html
  • 这是 Hexo 在生成 tagscategories 时,中文名称被转成了 UTF-8 的 octal 码。

  • 原因:

    • Hexo 目录下有中文标签或分类名。
    • Git / 终端没有正确显示 UTF-8。
  • 解决方法

    • 确保仓库支持 UTF-8 文件名(现代 Git 默认支持)。
    • 如果想彻底避免乱码,可以把标签或分类改成英文或拼音。

⚠️ 一般情况下,这个问题不会阻止部署,只是显示上会有乱码。


2️⃣ SSH 连接失败

报错核心信息:

APACHE
1
2
textConnection closed by ::ffff:0:c612:35 port 22
fatal: Could not read from remote repository.

原因通常是:

  1. 远程仓库地址写错
    很多用户 _config.yml 里可能写成:

    DTS
    1
    2
    3
    4
    yamldeploy:
    type: git
    repo: git@lb.github.com:lifuaini2019/2024bk.git
    branch: main

    这显然错误,因为 GitHub SSH 地址应该是:

    SCSS
    1
    textgit@github.com:用户名/仓库名.git
  2. 多账号 SSH key 冲突

    • Mac 上默认 SSH key 是 ~/.ssh/id_rsa
    • 如果之前有多个 GitHub 账号使用不同 key,可能导致 Hexo 推送失败。
  3. SSH Key 没加到 GitHub 或权限不足

    • 确认你在 GitHub → Settings → SSH Keys 中添加了公钥。

3️⃣ 解决方案

步骤一:修改 _config.yml

DTS
1
2
3
4
yamldeploy:
type: git
repo: git@github.com:lifuaini2019/2024bk.git
branch: main

注意:如果有多个 GitHub 账号,可通过 ~/.ssh/config 指定不同的 key。

步骤二:生成 SSH Key(如果还没生成)

BASH
1
2
3
bashssh-keygen -t rsa -b 4096 -C "你的邮箱" -f ~/.ssh/id_rsa_2024bk
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_2024bk

步骤三:配置 SSH 多账号(可选)

编辑 ~/.ssh/config

CRMSH
1
2
3
4
textHost github.com-2024bk
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_2024bk

然后 _config.yml 对应修改:

APACHE
1
2
yamlrepo: git@github.com-2024bk:lifuaini2019/2024bk.git
branch: main

步骤四:测试 SSH 连接

MARKDOWN
1
2
3
4
5
bashssh -T git@github.com

# 或者如果用多账号

ssh -T git@github.com-2024bk
  • 成功会显示:
ADA
1
vbnetHi 用户名! You've successfully authenticated, but GitHub does not provide shell access.

步骤五:Hexo 部署

CSS
1
2
3
bashhexo clean
hexo g
hexo d

4️⃣ 总结

  1. 中文标签文件名显示成转义符是正常现象,可通过英文标签避免。

  2. SSH 推送失败的根本原因是:

    • 仓库地址错误
    • SSH Key 没配置或权限不足
    • 多账号 SSH 冲突
  3. 通过正确配置 _config.yml + SSH Key + ~/.ssh/config,就能顺利部署 Hexo 到 GitHub。