Hexo

服务器Git部署

前提条件:本地ssh公匙(C:\Users\Reiki.ssh\id_rsa.pub),已配置服务器:

1
2
3
adduser git
chmod 740 /etc/sudoers
vim /etc/sudoers

root ALL=(ALL) ALL 下面添加

1
git    ALL=(ALL)   ALL

改回权限,设置git用户密码

1
2
chmod 400 /etc/sudoers
passwd git
1
2
3
su git
mkdir ~/.ssh
vim ~/.ssh/authorized_keys

粘贴 本地ssh公匙

本地测试

1
ssh -v git@111.1111.111.111

若免密登录,成功!

###准备两个目录

1.网站目录

1
2
mkdir /www/wwwroot/hexo
chmod -R 755 /www/wwwroot/hexo

2.git仓库目录

1
2
3
mkdir /home/git/repo
chown -R git:git /home/git/repo
chmod -R 755 /home/git/repo

创建git钩子

1
2
cd /home/git/repo
git init --bare hexo.git

创建钩子文件

1
vim /home/git/repo/hexo.git/hooks/post-receive

粘贴以下代码

1
2
#!/bin/bash
git --work-tree=/www/wwwroot/hexo --git-dir=/home/git/repo/hexo.git checkout -f

改权限钩子文件两个目录

1
2
3
4
5
chown -R git:git /home/git/repo/hexo.git/hooks/post-receive
chmod +x /home/git/repo/hexo.git/hooks/post-receive

chown -R git:git /www/wwwroot/hexo
chown -R git:git /home/git/repo

本地配置

_config.yml

1
2
3
4
deploy:
type: git
repo: git@43.143.120.36:/home/git/repo/hexo.git
branch: master

本地启动推送

1
2
hexo clean
hexo g -d

主题升级

主题目录下

1
2
3
git stash
git pull
git stash pop

若git仓库不安全报错

1
git config --global --add safe.directory E:/blog/Hexo/themes/butterfly