hexo deployed to centos remote server

Posted by xjake88x on Sun, 23 Feb 2020 03:23:50 +0100

Key paired to local and server

Prerequisite: Server has git tools and nginx server installed, git tools locally installed, hexo configured

Generate Local Key

The local terminal runs the command ssh-keygen-t RSA and returns continuously, generating a public key to store in C...In the / user/.ssh folder, the public key at the end of the pub is used

Server adds git users and gives them permissions

$ yum install git			#Run Command Installation without git installed
$ adduser git				#Create a user git
$ sudo passwd git			#Set git user password
$ chmod 740 /etc/sudoers	#Modify file permissions to allow users to read, write, and execute
$ vim /etc/sudoers			#Edit File

root  ALL=(ALL)   ALL		#Find here, add git user permissions below
git   ALL=(ALL)   ALL

$ chmod 400 /etc/sudoers  //Save Exit to Change Back Permissions

Create key file

$ su git						#Switch git users
$ mkdir ~/.ssh 					#Create.ssh folder
$ vim ~/.ssh/authorized_keys	#Create authorized_keys file

# They are key files that are hidden and not visible to the file manager, but can be found by accessing the / root/.ssh path or by cd/root/.ssh LS
# Then copy the public key from the id_rsa.pub file generated in win10 to the authorized_keys file, right-click vim and paste instead of opening the file with ftp Manager

$ chmod 600 /home/git/.ssh/authorized_keys #Set the file to be readable and writable
$ chmod 700 /home/git/.ssh 	#Make this folder freely accessible

Test git connection

The local terminal enters the command ssh-v git@server ip to test if it can connect without entering the server git user password (I will be able to connect confidentially later)

If the first step is unsuccessful, it's OK that you need a password to connect to each deployment

Server Create Warehouse

$ mkdir /var/repo   #Create a warehouse directory with git bare libraries behind it
$ chown -R git:git /var/repo  #Change the owner of the directory, note that it is chown
$ chmod -R 755 /var/repo  #Make this directory open for read-write execution
$ mkdir /var/www/hexo   #Create a directory to store site static files as the site root directory
$ chown -R git:git /var/www/hexo  #Change the directory owner to git user
$ chmod -R 755 /var/www/hexo   #Open Permissions
#Nginx I deployed nginx with the pagoda to create the site directly, and later it is also easy to manage the site
#You can also find the /etc/nginx configuration file nginx.conf to set the root directory of the site inside
server {
	        listen       80 default_server;
	        listen       [::]:80 default_server;
	        server_name  _;
	        root         /var/www/hexo;
	        index index.html index.htm;
	        # Load configuration files for the default server block.
	        include /etc/nginx/default.d/*.conf;
	        location / {

Build a bare git Library

$ cd var/repo
$ git init --bare hexoBlog.git #Create a bare library, but it's not empty
$ vim /var/repo/hexoBlog.git/hooks/post-receive  #Create a new hook file post-receive under the hooks directory and edit it with vim
#vim edit (press i) and paste the following two sentences, the paste mode of window s may be different

git --work-tree=/var/www/hexo --git-dir=/var/repo/hexoBlog.git checkout -f 

#This hook means that when a local submission is made to the server, the file is placed in the root directory of the site
$ chown -R git:git /var/repo/hexoBlog.git/hooks/post-receive
$ chmod +x /var/repo/hexoBlog.git/hooks/post-receive

Configure Hexo Site Files

Slide to Bottom

# Deployment
## Docs: https://hexo.io/docs/deployment.html
  type: git
  repo: git@The server IP:/var/repo/hexoBlog.git #This bare library is used solely for connections
  branch: master

Write at the end

This deployment was smoothly based on the two blogs below. The notes above remembered that the main reason for this detail was that both blogs had the same errors - the words were written incorrectly, but also the same mistake.The second command is detailed, but seems to be wrong in the steps for pairing keys, which are harmful!Lost a lot of time!



Twelve original articles were published. 2. Visits 3413
Private letter follow

Topics: git ssh Nginx vim