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

来源:互联网 发布:mac照片导入iphone x 编辑:程序博客网 时间:2024/04/27 16:21

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

FATAL bash: /dev/tty: No such device or addresserror: failed to execute prompt script (exit code 1)fatal: could not read Username for 'https://github.com': Invalid argumentError: bash: /dev/tty: No such device or addresserror: 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上了~~

1 0