I have a case when I need to move data from an old server: host1 to a new server: host2. The problem is host1 cannot see host2, but I can use another server (localhost) to SSH to both host1 and host2.

Imagine it should work like this: host1 -> localhost -> host2

How can I use rsync to copy files between host1 and host2? I tried this command on localhost server but it says The source and destination cannot both be remote.

 rsync -avz host1:/workspace host2:/rasv1/old_code-de
  • 2
    You could try scp -3 host1 host2. The option -3 means: "Copies between two remote hosts are transferred through the local host."
    – eblock
    Commented Apr 6, 2020 at 12:43
  • I did not find -3 option, as suggested by eblock, in mine rsync, nor in man pages on the internet (linux.die.net/man/1/rsync). Look here: unix.stackexchange.com/questions/183504/…
    – nobody
    Commented Apr 6, 2020 at 13:25
  • 1
    @nobody You will notice that eblock does not mention rsync.
    – Kusalananda
    Commented Apr 11, 2020 at 9:42

3 Answers 3


I ended up with the solution from https://unix.stackexchange.com/users/312074/eblock


scp -3 host1 host2

You can use tunneling to redirect the rsync using ssh.

Start logged as user@host1, and create the tunnel to host2 through your "localhost" (Let's call it "your_host" to avoid confusion):

ssh <your_host_user>@<your_host> -L 8080:<host2_ip>:22

Keep that terminal open, then on another terminal from host1 type:

rsync -avzh -e "ssh -p 8080" <source_file> <host2_user>@<target_folder>

Of course you can use any other port instead of 8080. As for using other method not involving ssh, I think it's possible but I didn't test.


As far as I am aware rsync does not support copying from remote server to remote server.

If you only need simple file copy you could just use scp with -3 option as pointed out by @eblock


If you need rsync you could mount both servers to local folder with sshfs

sshfs user@server1:/path/on/server1 /local/path1
sshfs user@server2:/path/on/server2 /local/path2

And than copy files between local folders:

rsync -av /local/path1 /local/path2

To unmount:

fusermount -u /local/path1
fusermount -u /local/path2

Though i'm not sure about the speed/performance of sshfs.

  • Using rsync on top of sshfs is a really bad idea (it disables most of its optimisations) Commented Apr 6, 2020 at 22:27

Not the answer you're looking for? Browse other questions tagged .