Hexo is quick to get up and running with its own blogging site, which can be deployed in a variety of ways. When deploying to Github, there were few problems, but when choosing to deploy to Aliyun ECS using Rsync, the Windows deployment pits appeared one by one.

Problems encountered

First take a look at the official deployment tutorial, which has the following short paragraph: Install Hexo-Deployer-rsync. $ npm install hexo-deployer-rsync –save

Modify the configuration

deploy:
  type: rsync
  host: <host>
  user: <user>
  root: <root>
  port: [port]
  delete: [true|false]
  verbose: [true|false]
  ignore_errors: [true|false]
Copy the code

Rsync does not exist

Git bash: hexo d: hexo d: hexo d: hexo d

INFO  Validating config
INFO  Deploying: rsync
'rsync' is not recognized as an internal or external command,
operable program or batch file.
Copy the code

Windows does not have rsync installed by default, so install cwrsync. After downloading several versions from the official website, various other problems occurred. Here, I completed the follow-up operations with version 5.5.0.

After downloading, the following operations are performed:

First, unzip the downloaded software package to the desired location, and then double-click cwrsync.cmd to start the installation. Normally, the home directory will be generated, but I did not generate it (in the screenshot, I manually added it later).

Add the bin directory to the environment variable to access the rsync.exe file. And then hexo D again. Ok, the following error occurs:

INFO Validating config INFO Deploying: rsync Could not create directory '/home/lazy5/.ssh'. Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: Error in rsync protocol data stream (code 12) at IO. C (226) [sender=3.1.2]Copy the code

The SSH directory is in the root directory of the user, and the corresponding public key has been added to the server. /home is a Linux directory structure. Several studies have shown that the SSH for this version of rsync is not the one we installed, but ssh.exe in the bin directory of Cwrsync, meaning that the key directory may not point to the user directory, but the installation directory of Cwrsync. So, in the installation directory, I created a /home/lazy5/.ssh directory.

At the same time, double-click the ssh-keygen.exe file in the bin directory and press Enter to generate the key pair in /home/lazy5/. SSH directory as follows:

Add the generated public key to authorized_keys for the server user, and try deploying it again. Still failed, check the following no permission error

No permission error reported

The first problem is the following excessive authority:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Permissions 0770 for '/home/lazy5/.ssh/id_rsa'are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.  Load key"/home/lazy5/.ssh/id_rsa": bad permissions
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Copy the code

Therefore, I removed the permissions for /home/lazy5/.ssh/id_rsa except for the owner lazy5.

After the above Settings, the problem of too high permissions is gone. In theory, this deployment will not be possible, but there are other permission problems in the actual operation, the specific screenshots are not available, listed as follows:

1. The deploy configuration uses root, causing the access to be denied. It is suggested to create a user for the operation of user rsync, and the user name should be the same as that of the local Windows computer. Here IS lazy5, and a similar user name has been created on the server.

Chown changes the permission of the directory to lazy5 and adds lazy5 to the root group because the newly created directory is not in the root group but belongs to user root.

3. Other permissions denied for server access: The public key login mode is not enabled over SSH. Modify the configuration file.

    1. vim /etc/ssh/sshd_config

2. Add the following configuration:

PubkeyAuthentication yes
PermitRootLogin yes
PasswordAuthentication no
RSAAuthentication yes
Copy the code

3. Reload the systemctl restart SSHD command

After successful upload, the domain name is 403

All done, access to the site appears 403, estimated to be a permission problem. View the file permissions in the hexo directory as follows:

Chmod 777 hexo-r can be accessed normally after deployment. However, after each deployment, you need to log in to the server to change permissions. So why did Rsync change permissions, and on what basis? The lazy5 permission is used to access the files deployed to the server.

Check local project directory properties. There is no Everyone in permissions, so add it again.

After redeployment, permissions are finally normal!

After the language

The above is the general record of the pits encountered in Hexo using Rsync, which may not be complete due to the omission of many records during the pit filling process, and will be supplemented in the future. In addition, as there are too many holes, I feel that pM2 deployment can be done directly here. It is estimated that hexo generate can achieve the same effect on the server. You can try and record it later.