关于 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实例用法及参数详解

rsync命令用法入门

rsync 的核心算法

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

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

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

转载于:https://my.oschina.net/leejun2005/blog/75007

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值