1 安装宝塔

2 创建网站
2.1 新建网站

2.2 网站目录

3 Git 环境配置
3.1 安装git
3.2 创建git用户
3.2.1 创建git用户

3.2.2 修改git用户的权限

3.2.3 进入 sudo 命令文件
找到root ALL=(ALL) ALL
,在下面添加git ALL=(ALL) ALL

3.2.4 修改文件夹权限

3.2.5 设置 git 用户的密码

3.3 配置 SSH 免密登录
3.3.1 服务端
1 2 3 4 5 6
| su git
cd ~ mkdir .ssh
|

3.3.2本地端
文件管理器中输入%homepath%
,会跳转到用户目录下

在当前目录打开cmd命令

3.3.3 上传公钥
将本地的公钥(id_rsa.pub)上传到服务器的/home/git/.ssh
目录下

3.3.4 服务端配置
新建authorized_keys
文件,并拷贝公钥的内容到该文件中,依次执行以下指令:
1 2 3 4 5 6 7 8 9 10
| cd ~/.ssh cp id_rsa.pub authorized_keys cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh
restorecon -Rv ~/.ssh
|

3.3.5 测试免密登录
进入本地计算机的 Git Bash,输入:
1
| ssh -v git@xxx.xxx.xxx.xxx(公网IP)
|

3.4 配置 Git 仓库
在服务器新建一个 Git 仓库,同时新建一个钩子文件
1 2 3 4 5 6
| cd ~ git init --bare hexo.git vi ~/hexo.git/hooks/post-receive
git --work-tree=/www/wwwroot/hexo --git-dir=/home/git/hexo.git checkout -f
|

授予钩子文件可执行权限
1
| chmod +x ~/hexo.git/hooks/post-receive
|

4 本地端配置
4.1 修改_config.yml
在本地计算机打开 Hexo 项目,我用的 vscode,修改_config.yml
文件中的deploy
:
1 2 3 4
| deploy: type: git repo: git@公网ip:/home/git/hexo.git branch: master
|

4.2 安装插件
1 2 3 4 5
| npm install hexo-deployer-git --save
npm install hexo-server
|

4.3 配置 Git 全局变量
本地终端执行一下命令
1 2 3
| git config --global user.email "xxxxxxxxxx@xx.com" git config --global user.name "xxx"
|

4.4 生成静态文件和发布博客
在 vscode 的终端中输入:
1 2 3 4 5 6 7 8
| hexo clean
hexo generate
hexo deploy
|

5 访问网站

参考: