I want to rsync files between two remote servers. I tried to follow the next solution of @roaima: https://unix.stackexchange.com/a/183516/137526, but I need a more delicate solution, for two reasons:

  1. One of the remote server has a non default port for ssh, so I need to specify the port with the -p option.
  2. I can ssh to both server, but I had to use different usernames, so it has to be explicit specified.

In addition, in the cited solution it is not clear with is the path on the source host and which one is on the destination one, as both appears as /var/www

I have tried different variation of the next command, but w/o success:

ssh -R localhost:50000:username1@dest_host:22 username2@source_host 'rsync -e "ssh -p 50000" -avzt --progress --partial /path/on/source/ localhost:/path/on/destination/'

2 Answers 2


What you are doing there is at least 'complicated'. As far is i understood, you connect to one server, and tell it to sync to another server.

For ease of use, you may specify port and user to use in the local ssh configuration for a particular host. for instance, if you add the following lines to the file ~/.ssh/config (/home/username2/.ssh/config) on the source_host:

machine dest_host
 user username1
 port 50000

You may rsync files to the dest_host from source_host with:

ssh username2@source_host 'rsync -e ssh /source/path/on/source_host dest_host:path_below_username1_home

Assuming, dest_host's sshd listens on port 50000. You may also want to look into the "-r" / "-u" option of rsync.

  • Maybe two remote servers's routing is unreachble.
    – fajin yu
    Commented Feb 19, 2021 at 2:06

The elegant solution I found is using scp.

scp -3 -Cp [email protected]:/path/file*.txt [email protected]:/path/

It works perfectly. Notice using two different usernames for two hosts. You can also use wildcards in file name like *.

You must log in to answer this question.

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