Is it possible to specify a different ssh port when using rsync?

Ketema picture Ketema · Dec 28, 2010 · Viewed 220k times · Source

I have been attempting the following command:

rsync -rvz --progress --remove-sent-files ./dir user@host:2222/path

SSH is running on port 2222, but rsync still tries to use port 22 and then complains about not finding the path, cause of course it does not exist.

I would like to know if it is possible to rsync to a remote host on a non-standard ssh port.

Answer

klapa picture klapa · Jan 7, 2011

Your command line should look like this:

rsync -rvz -e 'ssh -p 2222' --progress ./dir user@host:/path

this works fine - I use it all the time without needing any new firewall rules - just note the SSH command itself is enclosed in quotes.