How to Use Rsync with Non-Standard Port on Linux

Using Rsync with the non-standard port on Linux will help access a very flexible syncing solution while offering the most secure overall environment for its users. Follow this guide, so you can try this tool out in no time.

With all forms of vulnerabilities lingering around digital information nowadays, modern-day data usage has become a bit worrisome. Having said that, it is now almost mandatory for users to have the SSH default port number modified and altered to something that can’t be guessed easily. 

There is no denying that the security with default SSH ports isn’t very reliable, which makes the data syncing process a bit challenging for many. Thankfully, there’s a great workaround for this, and we’re talking about remote syncing.

It might sound complicated, especially for those who aren’t familiar with the process but getting all your files/folders synced with your remote server isn’t hard. In the following write-up, we’ll guide you on how to sync files and folders by employing Rsync with the non-standard SSH port seamlessly.

What is Rsync?

Rsync, aka the Remote Sync, is a fast, feature-rich, extremely versatile, and robust modern-day utility that is meant to aid individuals in copying and syncing their files, folders, and directories from any local hosts to the desired remote hosts and vice versa. 

Pre Requisites

Before learning how to use Rsync with the non-standard port on Linux, you must first configure the SSH port. If you don’t know, Rsync tends to use the default SSH port 22 to get the files synced over local and remote hosts. For that reason, it is crucial that you change the SSH port of the remote server.

Step 1: Get Inside the Configuration File

Open the SSH configuration file /etc/ssh/sshd_config with the help of an editor like vim, for instance. Launch the Terminal using the “Ctrl+Alt+T” key combination and run the following command:

$ vim /etc/ssh/sshd_config
Use Rsync with Non-Standard Port on Linux

Step 2: Make the Changes

Once you’re inside, look for the section that says “Uncomment.” From there, assign your desired port number. Although you can go with your choice, it is recommended that you pick something that’s hard to guess. Additionally, you should always ensure that the number is unique and isn’t already used. 

Step 3: Save the File

After inputting the port number, save the changes and exit for further processing.

Step 4: Restart SSH

Finally, invoke the restart sshd command and ensure that all the changes are successfully applied.

Input:

$ systemctl restart sshd
restart sshd

How to Use Rsync with the Non-Standard Port on Linux

Now that you’re done changing the SSH Port to the non-standard port, it is time you learn how to use Rsync with the non-standard port on Linux. To ensure that you won’t have a hard time understanding the whole process, we’ve summarized everything below.

Step 1: Get Your Files/Folders Synced

You should start off by syncing all your files and folders. Sync them by employing Rsync with the non-standard SSH port.

Input:

$ rsync -arvz -e 'ssh -p <desired port-number>' --progress --delete user@[name]remote-server:[destination]/path/to/remote/folder [destination]/path/to/local/folder
Use Rsync with Non-Standard Port on Linux

Let us consider two different systems in order to understand the process better. Suppose one represents a remote system while the other reflects the local entity. Here are the details for both:

Details for the Remote Server

  • IP Address: 192.168.1.877
  • User name: Distroid
  • Sync folder: /samplebackup1

Details for the Local Server

  • Operating System: Ubuntu V14.04
  • IP Address: 192.168.1.822
  • Sync folder: /home/test/samplebackup2

From this point, what we’ll do is try and sync all the existing contents sitting on the remote server’s /samplebackup1 folder to the same for the assumed local system /home/test/samplebackup2/.

Launch the Terminal and invoke the following command:

$ sudo rsync -arvz -e 'ssh -p 1431' --progress --delete [email protected]:/samplebackup1 /home/test/samplebackup2
sync files

Step 2: Verification

As soon as you’re done with the syncing process, it is always a good idea to invoke the ls command together with the -l flag and check the content of both the remote and the local folder.

Input 1: Checking the file contents of the remote system

$ sudo ls -l /samplebackup1/
verify sync with rsync

Input 2: Checking the file contents of the local system

$ sudo ls /home/test/samplebackup2/
sample backup

Once done, study the output and confirm if the process went smoothly.

But what if your system has a firewall? In that case, the firewall will restrict port 22. But don’t worry, this issue isn’t hard to resolve. The only thing you have to do is get the default port changed, and you’re ready to sync files without any issues.

The good thing about Rsync is that it is not only easy to use but also super-efficient, all thanks to its fast and secure nature.

And with that, you now know how to use Rsync with the non-standard port on Linux. As mentioned, the process bags some basic steps that can be performed by anyone with any level of expertise.

If this guide helped you, please share it.

Leave a Reply
Related Posts