Hexo 搭建个人博客教程 - 3 - 将本地hexo托管到github
非原创 java_world 发表于:2018-06-27 15:24:57
  阅读 :68   收藏   编辑

上一篇   Hexo 搭建个人博客教程 - 2 - 创建github帐号

添加ssh key到github

打开git bash或电脑任意地方右键,找到Git Bash Here 

帐号邮件配置

git config --global user.name "zhang.x" # ""里改成自己的
git config --global user.email "zhang.x@malian.tech" # ""里改成自己的

使用git config -l 查看

查看本机是否配置过ssh

cd ~/.ssh #进入ssh目录
rm *    #删除已有的

配置ssh key

cd ~
ssh-keygen -t rsa -C "zhang.x@malian.tech"  # service@faceghost.com 替换成你的邮箱地址

敲3次回车即可,输出

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:w.......Fw service@faceghost.com
The key's randomart image is:
+---[RSA 2048]----+
|  o. o..         |
|.. oo++          |
|..o =oo          |
|.+ * . .  .       |
| .=o.E. S   .     |
|  B =...         |
| . Xoo+.o        |
|  .o*oB+..       |
| o=+ ==B         |
+----[SHA256]-----+

打印提示我们的ssh存放在

c/Users/Administrator/.ssh/

打开该目录下的id_rsa.pub文件,复制全部

登录github,点击有右上角,找到Settings -> SSH and GPG keys

g_1


title随便写,Key粘贴刚刚id_rsa.pub文件内容

测试SSH KEY是否设置成功

命令

ssh -T git@github.com

输出

The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Hi FaceGhost! You've successfully authenticated, but GitHub does not provide shell access.

本地hexo项目托管到Github

修改_config.yml ,我的目录在D:\hexo\hexo

注意:配置文件中每个字段后要加一个空格再写值

该文件的最后

type: git
repository: git@github.com:malian-tech/malian-tech.github.io.git # 改成自己的
branch: master

image

安装hexo-deployer-git插件

cd /d/hexo/hexo/
npm install hexo-deployer-git --save

输出

npm WARN deprecated swig@1.4.2: This package is no longer maintained
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ hexo-deployer-git@0.3.1
added 31 packages in 23.611s

部署到Github上

依次执行

hexo clean  #清除缓存 网页正常情况下可以忽略此条命令
hexo generate   #生成静态页面至public目录
hexo deploy     #将.deploy目录部署到GitHub

执行hexo deploy 直到

Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.
Branch master set up to track remote branch master from git@github.com:FaceGhost/faceghost.github.io.git.
To github.com:FaceGhost/faceghost.github.io.git
 + ba67ed3...3477001 HEAD -> master (forced update)
INFO  Deploy done: git

查看

https://malian-tech.github.io/