hexo系列之Rsync使用中的问题

976 阅读5分钟

hexo系列之Rsync使用中的问题

hexo 官方文档:hexo.io/zh-cn/docs/ hexo部署官方文档介绍:hexo.io/zh-cn/docs/…

Rsync

引自官方介绍

  1. 安装 hexo-deployer-rsync。
 npm install hexo-deployer-rsync --save
  1. 修改配置。
deploy:
  type: rsync
  host: <host>
  user: <user>
  root: <root>
  port: [port]
  delete: [true|false]
  verbose: [true|false]
  ignore_errors: [true|false]
  1. 参数介绍
参数 描述 默认值
host 远程主机的地址
user 使用者名称
root 远程主机的根目录
port 端口 22
delete 删除远程主机上的旧文件 true
verbose 显示调试信息 true
ignore_errors 忽略错误 false
  1. rsync部署模块的工作方式

需要注意的是,要求您提供的实际上是一个能通过SSH登陆远程主机的Linux用户。Hexo会自动处理关于rsync使用的一切操作。因此,您需要在远程主机上为您的Hexo站点建立一个用户,并允许其通过SSH登陆。不过,这里的port,的确是指rsync监听的端口,请确保防火墙打开了该端口。

使用中遇到的问题

官方文档简单介绍了使用方法,我在使用过程中遇到了这些问题,个人整理下,如果有遇到同样问题的你,可以关注一下。

笔者环境: Windows10

安装cwRsync

因为使用windows,所以要有ssh环境,下载cwRsync,并且安装

懒人技巧: 关注“趣学程序”公众号,回复cwRsync即可获取安装包文件。

解压之后双击cwrsync.cmd,即为安装成功。会在当前目录下生成home目录

配置环境变量,右键`此电脑`-->`属性`-->`高级系统设置`-->`高级`-->`环境变量`-->`系统变量【PATH】`-->`编辑后面追加,cwrsync安装目录的bin目录文件路径`

创建本地公钥

进入到cwRsync安装文件的bin目录,在此目录打开cmd中执行ssh-keygen.exe,直接点击三次回车

看到类似下图就代表你创建成功了

查看cwRsync的home文件夹,可以看到生成的.ssh文件夹里的公钥和私钥,我们需要将公钥里面的内容复制到远程服务器上

id_rsa.pub公钥,右键编辑,复制出来

ssh-rsa AAAAB3NzaC1yc2PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPFL3u/4IiVVSHsdIo9WmrN5iiXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2Z2MtRhIkS+Q6X305X5UtmSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSuXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXPU83kv3Dx+DESD09RCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCsYv03/c23wvSGx2iOyg1G/ shaofeer@shaofeer-pc
  1. 复制到远程服务器的/home/(your username)/.ssh/authorized_keys 文件里面,如果没有.ssh文件夹,需要在服务器上执行ssh-keygen,如果没有authorized_keys文件,可以自己新建一个touch authorized_keys

2.chmod 600 authorized_keys #修改文件权限 3.chmod 700 .ssh #修改文件夹权限 4. 在服务器端做必要的ssh配置

  vim /etc/ssh/sshd_config #对sshd_config文件做如下修改

         #############################################

                   RSAAuthentication yes

                   PubkeyAuthentication yes

                   PermitRootLogin yes

        ##############################################

         修改完sshd_config文件后,重启ssh服务:service ssh restart


可以在`cmd`中测试远程免密`ssh`链接了

```cmd
D:\develop\cwRsync_5.5.0_x86_Free\bin>ssh [yourusername]@[host-ip]
Last login: Mon Jul  6 10:59:00 2020

Welcome to Alibaba Cloud Elastic Compute Service !

[shaofeer@shaofeer-pc ~]$

问题1

执行hexo部署


E:\project\web\person\MyNewBlog2020>hexo de
INFO  DPlayer.min.css is not found in this version of dplayer, skip it.
INFO  Deploying: baidu_url_submitter
INFO  Submitting urls
http://www.quxuecx.com/posts/535716537.html
http://www.quxuecx.com/posts/3632233996.html
{"remain":2927,"success":2}
INFO  Deploy done: baidu_url_submitter
INFO  Deploying: rsync
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
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]
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
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]

    at ChildProcess.<anonymous> (E:\project\web\person\MyNewBlog2020\node_modules\_hexo-util@1.9.1@hexo-util\lib\spawn.js:36:19)
    at ChildProcess.emit (events.js:310:20)
    at ChildProcess.cp.emit (E:\project\web\person\MyNewBlog2020\node_modules\_cross-spawn@7.0.3@cross-spawn\lib\enoent.js:34:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
INFO  Total precache size is about 5.42 MB for 171 resources.

上述问题需要检查你本机的公钥是否正确的放到远程的服务器上面去了。

问题2

执行hexo部署


E:\project\web\person\MyNewBlog2020>hexo de
INFO  DPlayer.min.css is not found in this version of dplayer, skip it.
INFO  Deploying: baidu_url_submitter
INFO  Submitting urls
http://www.quxuecx.com/posts/535716537.html
http://www.quxuecx.com/posts/3632233996.html
{"remain":2923,"success":2}
INFO  Deploy done: baidu_url_submitter
INFO  Deploying: rsync
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0770 for '/home/shaofeer/.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/shaofeer/.ssh/id_rsa": bad permissions
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
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]
FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
Error: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0770 for '/home/shaofeer/.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/shaofeer/.ssh/id_rsa": bad permissions
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
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]

    at ChildProcess.<anonymous> (E:\project\web\person\MyNewBlog2020\node_modules\_hexo-util@1.9.1@hexo-util\lib\spawn.js:36:19)
    at ChildProcess.emit (events.js:310:20)
    at ChildProcess.cp.emit (E:\project\web\person\MyNewBlog2020\node_modules\_cross-spawn@7.0.3@cross-spawn\lib\enoent.js:34:29)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
INFO  Total precache size is about 5.42 MB for 171 resources.

上述问题需要修改本机的私钥在本地的权限。

windows上修改权限附上我的配置

结尾

好记性不如烂笔头,本文为个人学习总结。

  • 笔者:shaofeer
  • 个人网站(首发):quxuecx.com
  • 邮箱: shaofeer@163.com
  • QQ:337081267
  • 公众号:“趣学程序”

我这里整理了很多的学习资料、编程源码、学习笔记、面试心得,如果有需要,可以通过关注“趣学程序”公众号来获取哟~

20200703005907544_13701