我想將目錄從伺服器同步到我的客戶端。我無法直接存取伺服器,但需要透過 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。現在我沒有立即暫停。