hexo d 失败的解决方法

解决过程

环境说明

客户端平台:  Windows10

博客托管平台:  GitHub

问题描述

在用 hexo d 更新 Hexo 静态博客时,报了以下错误

1
2
3
FATAL bash: /dev/tty: No such device or address
error: failed to execute prompt script (exit code 1)
fatal: could not read Username for 'https://github.com': Invalid argument

验证问题所在

验证本地文件是否出错

1
2
3
4
# 启动本地服务器
hexo server

# 在浏览器输入 http://localhost:4000/

经过以上操作发现本地文件一切正常

与 GitHub 的连接问题

从报的错中可以推断出差不多是与 GitHub 的连接问题

解决方案

通过搜索引擎查得到相应的解决方案

归纳如下:

1.重新生成 SSH key

1
2
3
4
5
# 在CMD中输入以下命令
ssh-keygen -t rsa -C "Github的注册邮箱地址"

# 一直按Enter知道出现以下
Your public key has been saved in /c/Users/user/.ssh/id_rsa.pub.

用 Sublime 打开 /c/Users/user/.ssh/id_rsa.pub 并复制其内容

访问 GitHub – Settings – SSH and GPG keys – New SSH key

Title:  blog       Key:  id_rsa.pub 的内容

2.修改站点配置文件 _config.yml

1
2
3
4
5
6
# 把deploy中的repo由注释的格式改为以下格式
deploy:
type: git
#repo: https://github.com/username/username.github.io.git
repo: git@github.com:username/username.github.io.git
branch: master

验证

1
2
3
4
# 在CMD中依次输入以下命令,结果不存在报错,Hexo博客能正常更新
hexo clean
hexo g
hexo d
------ 本文结束------
如果对您有帮助的话请我喝瓶水吧!