解决用Hexo和GitHub搭建博客时hexo d命令报错问题

这两天学着使用hexo和github page搭建个人博客
到使用hexo deploy自动部署到github page的时候出现了错误:

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
Error: 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

这里写图片描述

在服务器上部署一点问题都没有,但是在本地部署是就一直报这个错误
最后把_config.yml中的git仓库链接改成了ssh链接,然后又给git账户增加了ssh key才解决了问题。

具体方法如下:

hexo配置

要使用自动部署首先要安装hexo-deployer-git工具:

$ npm install hexo-deployer-git --save

配置_config.yml中的deploy:

deploy:
 type: git
 repo:git@github.com:your_github_user_name/your_github_user_name.github.io.git
 branch: master

注意:这里的repo需要设置成你git仓库的ssh链接


生成 ssh key

命令行中输入:

$ ssh-keygen -t rsa -C greenovia@qq.com(换成你的邮箱地址)

接着出现的一些步骤都可以回车跳过,如下:
这里写图片描述

这样在 /c/Users/Administrator/.ssh/id_rsa文件中就生成了公钥


配置github账户的ssh key

打开id_rsa.pub文件将一整串公钥拷贝下来

进入你的github账户设置,在ssh and GPG keys中新增一个ssh key,如下
这里写图片描述

把刚刚拷贝出来的公钥粘贴到key中,title放空就好

这里写图片描述

验证ssh key:

$ ssh -T git@github.com

出现下面的语句说明你的ssh key已经配置好了

Hi wispyoureyes! You've successfully authenticated, but GitHub does not provide shell access.

初始化本地git仓库

设置Git的user name和email:

$ git config --global user.name "wuyanqina"
$ git config --global user.email "greenovia@qq.com"(换成你的邮箱地址)

在本地的hexo init生成的文件夹中初始化git仓库:

$ git init

将本地仓库和远程仓库连接(这一步骤可以不做):

$ git remote add origin git@github.com:your_github_user_name/your_github_user_name.github.io.git(远程仓库ssh地址) 

做完以上这些步骤,说明你的仓库可以使用ssh方式来上传下载代码,而不需要输入用户名和密码了


网站部署

$ hexo clean  //清除缓存文件db.json和已生成的静态文件public
$ hexo g   //生成网站静态文件到默认设置的public文件夹
$ hexo d   //部署网站到设定的仓库

部署成功后会提示:
这里写图片描述

这样你的博客就部署到了page上了~~

  • 18
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 17
    评论
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值