關於 rsync 中: 和 :: 及 rysnc 和 ssh 認證協議的區別
今天上午同事問我
rsync -av /SRC [email protected]:36000::/DEST
為何報 port 22 refused 的錯誤?
因為我們機器都是修改了 ssh 埠的,預設22埠是登入不上ssh的,
同事的本意是想修改rsync的傳輸埠,但這條語句卻寫錯了,錯誤有2處:
雙冒號 :: 和 port 格式指定錯誤,
(1)雙冒號 “::”的用法:
rsync 傳輸檔案前需要登入認證,那麼這個過程用到的協議有兩種:ssh 和 rsync
何時用ssh 協議呢?
我們平時用的 rsync -av /SRC [email protected]:/DEST 就是預設用的 ssh 協議
這種方式預設是省略了 -e ssh 的,與下面等價:
rsync -av /SRC -e ssh [email protected]:/DEST
當遇到要修改埠的時候,我們可以:
rsync -av /SRC -e "ssh -p36000" [email protected]:/DEST
何時用rysnc協議呢?
rsync -av /SRC rsync://[email protected]:36000/modual/DestPath
注意:這條語句顯示的指明瞭使用rsync認證協議,port後的modual是rsync服務端配置檔案rsyncd.conf
裡面配置的模組名,模組裡面會包含一些使用者名稱、密碼、路徑等認證資訊。
使用rsync認證,還有一種寫法:
rsync -av /SRC --port=36000 [email protected]::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使用詳解