This blog will briefly introduce how to deploy Hexo to a remote server, which can be synchronized and updated through git.
- SSH Configuration
- Server Deployment
- Hexo Configuration & Deployment
In order to connect the remote server, we need the SSH Key.
ls -al ~/.ssh
If the key exists, there will be a
id_rsa.pubfile, you can directly copy the SSH Key in that file. SSH Key path:
/Users/(your user name)/.ssh/id_rsa.pub
If there is no
SSH Keygenerated before, you can first set up your git account, then generate the
git config --global user.name 'your_name'
git config --global user.email 'your_email'
ssh-keygen -t rsa -C 'your_email'
My remote server is on Tencent Cloud, with its OS: CentOS 8.2. We can connect the server remotely through the server console.
Switch to root account:
sudo su root
# check whether git is installed: git --version
Find the following content, and add the line below:
## Allow root to run any commands anywhere
Save and exit the file, then change the permissions:
chmod 400 /etc/sudoers
Set up git account and password:
sudo passwd git
Switch to git user, create a
~/.ssh folder and
SSH Key in that file, then save and exit.
Enter the following command to grant permissions:
chmod 600 /home/git/.ssh/authorized_keys
In the local terminal, test whether you can connect and log in to the git on the remote server side:
$ ssh -v git@your_server_ip
Create a project repository on the server side and grant permissions:
Create a root file of the website and grant permissions:
Initialize a git repository:
Create a hook for deployment:
Enter the edit mode, then paste the two lines of code below:
Save and exit, and then modify permissions:
chown -R git:git /www/repo/hexo.git/hooks/post-receive
Now the git repository is all set up.
I used BT panel to install Nginx. First we need to install the BT panel:
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh
Then install the free version of Nginx in the BT store.
Add a site in the BT panel and set the root directory to our project root
Restart the BT panel:
service bt restart
Open Hexo project in the local
config.yml file, modify the following configurations:
At the server side:
chown -R git:git /www/repo/
At the local side, deploy Hexo with the command:
hexo d -g
Now that the Hexo deployment is completed.