Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am a happy user of rsync -e ssh and use it to synchronize data between my machine and a remote host using

rsync -avz -e ssh me@hostA:~/folder ~/folder

And this did what I needed until now.

I am now working with a configuration where the access is a bit more complicated. Suppose now ~/folder is on hostB, but hostB is not directly accessible from my machine, but only indirectly via hostA.

So if I only want to see the folder on hostB. I first need to ssh to hostA, then to hostB after which I can see my files in ~/folder on the remote host.

My question now is, what is the (best) method to use rsync directly between my machine and hostB?

Unfortunately this is the configuration I need to work with. Assume there is no possibility to temporarily store the data on hostA itself.

share|improve this question
up vote 8 down vote accepted

Have a look at How do I connect to a pc through another pc using ssh

You create a new ~/.ssh/config entry with the name tunnelb:

Host tunnelb
HostName hostB
User user
ProxyCommand ssh user@hostA nc %h %p

If you have a recent version of ssh you can use Proxycommand ssh user@hostA -W %h:%p instead. This is preferred as it does not rely on nc

Now you can just use rsync -e ssh tunnelb:~/folder ~/folder as it will use the defined entry in ~/.ssh/config.

share|improve this answer
Got it to work, thanks! – Bernhard Jul 15 '12 at 9:42

Variant 1:

First, start ssh on hostA permanently with local port forwarding in another terminal. E.g.:

ssh -N -v -L 22022:hostB:22 hostA

Then, "feed" rsync with ssh to localhost:22022. One variant is to write to ~/.ssh/config:

Host hostB
HostName localhost
Port 22022

Variant 2:

Replace -e ssh with -e to some script which contains:

ssh hostA 'ssh hostB' "$@"

I didn't try it so some details would be elaborated additionally.

share|improve this answer
Thanks for your hint. Was not able to successfully rsync yet. For the portforwarding I get an errormessage like debug1: Unspecified GSS failure. Minor code may provide more information Credentials cache file '/tmp/krb5cc_1000' not found. For the second variant I get bash: hostA: command not found. I will puzzle a bit on you suggestion, any more hints more than welcome – Bernhard Jul 15 '12 at 9:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.