How to Sync Files/Directories Using Rsync with Non-standard SSH Port

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.

Rsync Files Over SSH Non-standard 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. For more details about rsync, check man pages:

Conclusion

Syncing files/folders using Rsync with SSH is not only easy, but also fast and secure method. If you’re behind a firewall that restricts port 22, no worries. Just change the default port and sync files like a pro.

6 Responses

If you get this article then you HAVE to take it to the next level. And yes — there are various ‘better’ ways to change/specify the ssh port and the connection ABSOLUTELY should be key’d, but I digress…

The next level is doing a differential HARD-linked backup set.
ie: I’ve already backed up the remote directory to local backup “1”.

--link-dest=/my_backups/1

Put it all together (well, as I do it) for the second and onward backup:

What this does only transfer new (or changed) files via rsync, otherwise we already have the file in the previous backup set, HARD-link to the file.
This takes up no more space (except using another inode pointing to the data) — and the data exists until the last linked file is deleted.

I have servers rsync’ing multiple times per hour allowing for snapshots, if you will, going back many many months with minimal overhead for ALL those backups (hundreds) — only new data. Wipe the oldest as space requires…

lol. Security reasons.. did you ever hear about certificates?
at least explain your concerns.
in my case I noticed a Rapid decrease in attempts to login to my Servers by just removing root from password as well as key auth.
unless someone knows your account name nobody could Start bruteforcing your password. though its better to just rely to passphrased ssh Keys only.

The right way to do this is to put the port in the .ssh/config file, that way you don’t need to remember the port numbers. In addition to security the other advantage is that it allows you access many machines from a single IP address. On your router you need to port forward each port to the appropriate machine then you need to alias the different names to the same IP (this is easy to do if you are using dyn.com as your dynamic DNS service, I’m sure it’s trivial with any DNS service). Once you’ve done that you can ssh into different machines by specifying the port number. Below is an example .ssh/config.