How to use rsync with non standard ssh port
rsync is a useful utility when transferring files between servers. It can be used to copy files over SSH to a remote server and vice versa. I deal with all kinds of migrations every day. So rsync has become tool I use everyday.
Today, I was migrating a website to a remote server that had a custom SSH port. By default, rsync will try to connect to remote server on port 22. Connection will fail because the remote server is configured to use port 2222 as the SSH port. So I had to specify the custom SSH port in the command. The solution was to add the following flag to the rsync command.
-e 'ssh -p 2222'
So my final command looked something like this,
rsync -e 'ssh -p 2222' --progress -a /home/username/public_html/ firstname.lastname@example.org:/home/username/public_html
This rsync command pushes local file to a remote server with custom SSH port 2222. The local SSH port doesn't matter in this case.