Pages

Thursday, June 29, 2017

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
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:
# man rsync
Or refer our previous guide from the link below.
  1. Rsync: 10 Practical Examples of Rsync Command in Linux

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.
In RPM based systems such as RHELCentOS, and Scientific Linux 7, you need to allow the new port through your firewall or router.
# firewall-cmd --add-port 1431/tcp
# firewall-cmd --add-port 1431/tcp --permanent
On RHEL/CentOS/Scientific Linux 6 and above, you should also update selinux permissions to allow the port.
# iptables -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 1431 -j ACCEPT
# semanage port -a -t ssh_port_t -p tcp 1431
Finally, restart SSH service to take effect the changes.
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
                                                    ► Read more: http://adf.ly/1nBgiW
      ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

No comments:

Post a Comment