Rsync over SSH with specific port

To execute a rsync over a ssh connection, we need to add the option -e and the ssh connection to rsync with the specific port we want to use, in this case 2222:

rsync -e "ssh -p 2222" origin destiny

Where origin is the remote or source host from where we want to copy and destiny is the target host.

To add more information to rsync, we can append more options:

rsync -vah --stats --progress -e "ssh -p 2222" origin destiny

That will give us the statistics of the transfer and a progress.

Keep SSH session alive

To avoid having your SSH session timeout due to inactivity, you can tweak your server and client settings.

Server side

Edit the fie: /etc/ssh/sshd_config
Set the values:

ClientAliveInterval 120
ClientAliveCountMax 720

Client Side

Edit the file: ~/.ssh/config
Set the value:

ServerAliveInterval 120

That should do the trick!