关于 rsync 中: 和 :: 及 rysnc 和 ssh 认证协议的区别

时间:2022-04-28
本文章向大家介绍关于 rsync 中: 和 :: 及 rysnc 和 ssh 认证协议的区别,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

今天上午同事问我 

rsync -av /SRC root@172.17.256.211:36000::/DEST

为何报 port 22 refused 的错误?

因为我们机器都是修改了 ssh 端口的,默认22端口是登录不上ssh的,

同事的本意是想修改rsync的传输端口,但这条语句却写错了,错误有2处:

双冒号 :: 和 port 格式指定错误,

(1)双冒号 “::”的用法:

rsync 传输文件前需要登录认证,那么这个过程用到的协议有两种:ssh 和 rsync

何时用ssh 协议呢?

我们平时用的  rsync -av /SRC root@172.17.256.211:/DEST 就是默认用的 ssh 协议

这种方式默认是省略了 -e ssh 的,与下面等价:

rsync -av /SRC -e ssh root@172.17.256.211:/DEST

当遇到要修改端口的时候,我们可以:

rsync -av /SRC -e "ssh -p36000" root@172.17.256.211:/DEST

何时用rysnc协议呢?

rsync -av /SRC rsync://root@172.17.256.211:36000/modual/DestPath

注意:这条语句显示的指明了使用rsync认证协议,port后的modual是rsync服务端配置文件rsyncd.conf

里面配置的模块名,模块里面会包含一些用户名、密码、路径等认证信息。

使用rsync认证,还有一种写法:

rsync -av /SRC --port=36000 root@172.17.256.211::modual/DestPath

注意:这种写法不需显示指定 rsync 协议,而是根据 :: 来识别的,端口自己用 --port 指定。

而且这里 modual 前面没有 / 的。

总结: 双冒号:: 是用在 rsync 协议里面的,: 一般用在ssh协议里面,这两种用法各有千秋:

rsync协议你需要在rsync服务端配置模块,这增加了运维工作量,但是安全,因为不需要对客户公开服务器帐号密码。

ssh协议方便,不需配置,拿到服务器帐号密码即可开工,但是对客户是暴露的,有安全风险。

还需要注意的是用rsync协议认证的时候,后面跟的是模块名,而不是路径,这点要注意。

(2)关于 rsync --port 的man文档如下:

rsync 客户端 --port 

 --port=PORT

              This  specifies  an alternate TCP port number to use rather than

              the default of 873.  This is only needed if you  are  using  the

              double-colon  (::) syntax to connect with an rsync daemon (since

              the URL syntax has a way to specify the port as a  part  of  the

              URL). 

rsync 服务端 --port

 --port=PORT

              This  specifies  an  alternate TCP port number for the daemon to

              listen on rather than the default of 873.  See also  the  "port"

              global option in the rsyncd.conf manpage.

(3)附一些参考文档:

rsync实例用法及参数详解

http://hi.baidu.com/leejun_2005/item/672c31d4c12a8b1b20e25041

rsync命令用法入门

http://hi.baidu.com/leejun_2005/item/a04d17c4cf24547088ad9e7c

rsync 的核心算法

http://hi.baidu.com/leejun_2005/item/11651fc379229f52bdef69b7

Linux下同步工具inotify+rsync使用详解

http://segmentfault.com/blog/seanlook/1190000002427568