Linux

rsync 通過多路 SSH 連接和多個 jumphosts

  • December 1, 2021

我需要通過多個跳轉主機將文件從遠端主機同步到我的本地機器。我想使用共享 SSH 連接,這樣我就不必在某些跳轉主機上多次送出 2FA。

這個想法是我創建一個主連接

ssh user@jumphost01

然後是其他連接

ssh -J user@jumphost01,user@jumphost02 root@target01
...

共享連接控製文件~/.ssh/如下

control:target01:22:root
control:jumphost01:22:user
control:jumphost02:22:user

現在我希望我可以使用 rsync 遠端文件

rsync -azv -e 'ssh -o ControlMaster=auto' root@target:/somePath/someFile someFile
or
rsync -azv root@target:/somePath/someFile someFile
or    
rsync -azv -e 'ssh -F /root/.ssh/config' root@target:/somePath/someFile someFile

但我收到 rsync 錯誤

receiving incremental file list
someFile
WARNING: someFile failed verification -- update discarded (will try again).
someFile
ERROR: someFile failed verification -- update discarded.

sent 68 bytes  received 317 bytes  770.00 bytes/sec
total size is 305  speedup is 0.79
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1819) [generator=3.2.3]

rsync 能夠連接到目標,但文件傳輸不成功。

rsync 版本

local machine - rsync  version 3.2.3  protocol version 31
target machine - rsync  version 3.2.3  protocol version 31

TLDR;

我在沒有 SSH 主連接的情況下測試了 rsync 命令

rsync -azv -e 'ssh -J user@jumphost01,user@jumphost02' root@target01:someFile .
One-time password (OATH) for `user': 
Password: 
receiving incremental file list
someFile
WARNING: someFile failed verification -- update discarded (will try again).
someFile
ERROR: someFile failed verification -- update discarded.

sent 68 bytes  received 2,767 bytes  195.52 bytes/sec
total size is 18,976  speedup is 6.69
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1819) [generator=3.2.3]

並且仍然得到相同的錯誤。

動態連結庫存在一些問題。

# apt update && apt upgrade

在遠端機器上解決了這個問題。

引用自:https://serverfault.com/questions/1083667