Server Fault is a question and answer site for system and network administrators. 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

The following command is working as expected.

ssh soak@ "ssh soak@ 'cat test.txt'" > /home/shantanu/test.txt

What I need to do is to copy the entire directory instead of a single file.

Is it possible to use rync with SSH tunneling?

share|improve this question
up vote 2 down vote accepted

You could pipe tar.


ssh soak@ "ssh soak@ 'tar cf - test_directory'" | tar xf -
share|improve this answer

You can use scp to copy single or multiple files and also use rsync with an ssh transport:

scp -r localdirectoryname username@hostname:/remotepath


rsync -av localdirectory username@hostname:/remotepath 

Both programs also work the other way round, with the remote part as the origin and the local as the destination.

See man scp and man rsync.


If you indeed need an intermediate server, you could use ssh port forwarding:

In one shell, use this command to establish a port forwarding:

ssh -NL 10022: soak@

This connects port 10022 on your local machine with port 22 on, but won't open a shell, instead just blocks until you terminate it.

Afterwards, on another shell/xterm, you can use either

scp -r -P 10022 localpath soak@localhost:/remotepath 

but have to be aware that soak@localhost actually points to soak@ when entering your credentials.

Edit 2, now featuring rsync

As you specifically asked about rsync, here is how to use rsync instead of scp. It requires the same port forwarding enabled as the scp variant:

rsync -av --rsh="ssh -p 10022" localpath soak@localhost:/remotepath 

and again remember that you are actually connecting to soak@

share|improve this answer
Does it connect to the intermediate server before copying data to remote host? – shantanuo Sep 28 '11 at 7:27
Maybe you should describe your requirements a bit better, especially why you need an intermediate server. Anyway, see my edit. – Sven Sep 28 '11 at 7:48

Another way is use SSH Port Forwarding.

First, run the following command on your computer:

$ ssh -N -f -L 2302: soak@

This allocated a socket to listen to port 2302 on localhost. Whenever a connection connect to this port, it will be forwarded to

So you can copy a folder on to your machine with:

$ scp -r -P 2302 soak@localhost:/path/to/folder /path/to/destination/dir
share|improve this answer

Also available is ssh's ProxyCommand.

From Undeadly:

Host internal.hostname.tld internal
  User          merdely
  HostName      internal.hostname.tld
  ProxyCommand  ssh merdely@gateway.hostname.tld nc %h %p 2> /dev/null
share|improve this answer

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.