hexo+git一步一坑搭建博客

根据这篇文章使用hexo+git搭建真正属于自己的博客的过程中是很顺利的,但是还是在部署到远程仓库的时候还是遇到了以下几个问题:

1
2
3
4
deploy:
type:git
repository: [email protected]:xxxxxx.githup.io.git
branch: master

1.修改了配置_config.yml文件之后,执行部署命令 hexo g/ hexo s,报错如下:

1
2
FATAL bad indentation of a mapping entry at line 81, column 13:
repository: https://github.com/NightSkyWat ...

原因:hexo语法比较严格,在修改配置文件_config.yml之后,一定要检查冒号后面的空格!!!检查冒号后面的空格!!!检查冒号后面的空格!!!

解决:将修改部分type/repository/branch后面都有一个空格

2.修改问题1之后,执行部署命令hexo d,报错如下:

1
ERROR Deployer not found: git

原因:部署远程博客前,需要安装git
解决:执行该命令 npm install hexo-deployer-git --save

3.使用SSH KEY,本地生成id_rsaid_rsa_pub文件,并复制id_rsa_pub文件中的内容添加到帐号之后,部署(hexo d)报错:

1
2
3
4
5
Permission denied (publickey).
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: http://hexo.io/docs/troubleshooting.html

测试当前的SSH是否配置成功,在git bash 中执行命令ssh -T [email protected]报错如下:
Permission denied (publickey).

原因:说明当前SSH没有配置成功

解决:
请确保以下2步均做到
1、远程服务器已经有了对应于本地主机上公钥
2、本地主机ssh服务开启(windows上是ssh-agent.exe运行),并且本地主机私钥要包含在ssh服务列表中

第一步已经完成,:已经将id_rsa_pub文件中的内容添加到了github帐号

检查本地私钥是否存在于ssh服务中

1
2
cd ~/.ssh
eval 'ssh-agent -s'

如果运行这句出现Could not open a connection to your authentication agent,那么就先运行
ssh-agent bash
再运行
ssh-add -l
如果不存在,需要添加进去
ssh-add ~/.ssh/id_rsa
添加完成之后,再执行ssh -T [email protected]测试SSH是否配置成功!!!

如果出现以下内容说明配置成功

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

4.执行终端命令hexo s,并在浏览器里输入https://localhost:4000后,可以预览到修改的相关内容,但是部署到远程仓库后(成功部署),打开对应的http://username.githup.io网址却出现以下充斥着形形色色广告的界面,到底是什么原因导致的呢?

仓库名称错误.png
最后经过排查找出错误原因:
因为自己错误的拼写习惯,错把github拼成了githup,
修改了 userName.github.io_config.ymlrepository:键值之后,顺序执行 hexo clean / hexo g /hexo d命令重新部署到远程仓库, 并进入对应的 http://username.github.io

###大功告成!!!

参考
github设置添加SSH
Permission denied (publickey)
Hexo博客搭建中的坑
5分钟 搭建免费个人博客