github部署hexo
本地ssh连接 GitHub
创建密钥
确保下载了git后输入命令1
2git config --global user.name "你的 GitHub 用户名"
git config --global user.email "你的 GitHub 邮箱"
- 用户名执行命令:
1
git config --global --add safe.directory D:/hexo/.deploy_git
- 指定密钥文件,在保存密钥文件的目录中创建文件:config
1
2
3
4
5Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
创建 SSH 密匙(可以-f指定输出目录)1
ssh-keygen -t rsa -C "你的 GitHub 邮箱"
什么都不用管,一路回车就行,创建好之后可以在.ssh看到有id_rsa.pub(.pub是公钥,id_rsa是私钥)。
打开 id_rsa.pub 并复制里面的内容。
在 GitHub 中添加 SSH 密钥
回到 GitHub,进入 Settings:
选择左边栏的 SSH and GPG keys,点击 New SSH key:
Title 随便取,然后把 id_rsa.pub 里面的内容到复制到 Key 中,点击 Add SSH key:
保存完毕本地验证一下连接1
ssh -T git@github.com
出现 “Are you sure……”,输入 yes 回车确认,若出现下图的提示即连接成功:
创建 GitHub 仓库
GitHub 的主页 repository 中点击右上角的 New:
填写基本信息:
Repository name 中输入用户名.github.io,一定要是这个名字!
勾选 Add a README file
填好后点击 Create repository 创建仓库
上传 hexo 程序到 GitHub
需要先安装 hexo-deployer-git:
npm install hexo-deployer-git --save
修改_config.yml 文件末尾的 Deployment 部分:
修改成如下(修改为你的用户名与仓库名)1
2
3
4deploy:
type: git
repo: git@github.com:w00123/w00123.github.io.git
branch: gh-pages
修改完成保存后运行1
2hexo c
hexo d
出现下面的提示说明已经把网站上传到 GitHub 了:
然后我们需要在库设置(Repository Settings)中将默认分支设置为_config.yml 配置中的分支名称。
然后在 pages 页面调整源分支:
访问用户名.github.io就可以看到默认 hexo 了。















