Today, we will be discussing about how to sync files using rsync with non-standard SSH port. You might wonder why do we need to use non-standard SSH port? It is because of security reasons. Everybody knows 22 is the SSH default port.
So, It is mandatory to change your SSH default port number to something different which is very hard to guess. In such cases, how will you sync your files/folders with your Remote server? No worries, It is not that difficult. Here we will see how to sync files and folders using rsync with non-standard SSH port.
As you might know, rsync, also known as Remote Sync, is a fast, versatile, and powerful tool that can be used to copy and sync files/directories from local to local, or local to remote hosts
Change SSH Port to Non-standard Port
As we all know, By default rsync uses default SSH port 22 to sync files over local to remote hosts and vice versa. We should change our remote server’s SSH port to tighten the security.
To do this, open and edit the SSH configuration /etc/ssh/sshd_config file:
# vi /etc/ssh/sshd_config
Find the following line. Uncomment and change the port number of your choice. I recommend you to choose any number which is very hard to guess.
Make sure you are using a unique number which is not used by existing services. Check this netstat article to know which services are running on which TCP/UDP ports.
For example, here I use port number 1431.
[...] Port 1431 [...]
Save and close the file.
Don’t forget you need to allow the new port through your firewall or router.
How to Rsync with non-standard SSH Port
Run the following command from the terminal to sync files/folders using Rsync with non-standard ssh port.
Syntax:
# rsync -arvz -e 'ssh -p <port-number>' --progress --delete user@remote-server:/path/to/remote/folder /path/to/local/folder
Let us sync the contents of remote server’s /backup1 folder to my local system’s folder /home/sk/backup2/.
$ sudo rsync -arvz -e 'ssh -p 1431' --progress --delete tecmint@192.168.1.103:/backup1 /home/sk/backup2
Sample Output
tecmint@192.168.1.103's password: receiving incremental file list backup1/ backup1/linux-headers-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb 752,876 100% 13.30MB/s 0:00:00 (xfr#1, to-chk=2/4) backup1/linux-headers-4.3.0-040300_4.3.0-040300.201511020949_all.deb 9,676,510 100% 12.50MB/s 0:00:00 (xfr#2, to-chk=1/4) backup1/linux-image-4.3.0-040300-generic_4.3.0-040300.201511020949_amd64.deb 56,563,302 100% 11.26MB/s 0:00:04 (xfr#3, to-chk=0/4) sent 85 bytes received 66,979,455 bytes 7,050,477.89 bytes/sec total size is 66,992,688 speedup is 1.00.
Source : https://www.tecmint.com/sync-files-using-rsync-with-non-standard-ssh-port/