我想将目录从服务器同步到我的客户端。我无法直接访问服务器,但需要通过 ssh 网关进行跳转。从我的“.ssh/config”:
Host gw
User ab123456
HostName gw.somewhere.ac.uk
IdentityFile ~/.ssh/id_dsa.pub
ServerAliveInterval 60
Host remote
User me
HostName remote.somewhere.ac.uk
IdentityFile ~/.ssh/id_dsa.pub
ProxyCommand nohup ssh gw netcat -w1 %h %p
ServerAliveInterval 60
它适用于交互式ssh
会话,但rsync
会失败。有时立即,有时几秒钟后,总是在复制任何文件之前:
$ rsync -av remote:/path/to/somewhere/ somewhere/
nohup: redirecting stderr to stdout
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(226) [Receiver=3.1.0]
$ rsync -av remote:/path/to/somewhere/ somewhere/
nohup: redirecting stderr to stdout
Access to this system is monitored etc. etc.
receiving incremental file list
Write failed: Broken pipe
rsync: connection unexpectedly closed (12288 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(226) [receiver=3.1.0]
rsync: connection unexpectedly closed (16336 bytes received so far) [generator]
rsync error: unexplained error (code 255) at io.c(226) [generator=3.1.0]
netcat
我认为这个问题与机器的网关有关gw
。当需要使用多跳连接时,如何正确使用rsync?
我使用 netcat 是因为我的同事给了我这个配置文件,它适用于普通的 ssh。
请注意,与情况不同这个问题rsync -av
,当我替换为时,我遇到了同样的问题scp -pr
(并且我确实需要rsync
正确同步的能力)。
答案1
我可以通过替换让它工作
#ProxyCommand nohup ssh gw netcat -w1 %h %p
和
ProxyCommand nohup ssh gw -W %h:%p
适用于现代 OpenSSH。现在我没有立即暂停。