Most Linux system users have changed the default SSH port to some non-standard ports for security. In this condition, you need to specify an SSH port on a non-standard port to connect the rsync command. This article will see how to copy data using rsync with non-standard ports. Let’s start by changing the SSH port to a non-standard port.
How to Change SSH Port to Non-standard Port
We need to change the SSH port of our remote server to tighten the security. As we already know, rsync uses the default SSH port 22 to sync files from remote to localhost and vice versa.
To change the SSH port to a non-standard port, open and edit the SSH configuration /etc/ssh/sshd_config file:
Please find the following lines and change the port number according to you by uncommenting it. Any number you choose can be difficult for others to choose.
We need to allow the new port through our router and firewall in RPM-based systems such as Scientific Linux 7, CentOS, and RHEL.
firewall-cmd --add-port 1431/tcp --permanent
To allow the port, SELinux permissions have to be updated.
semanage port -a -t ssh_port_t -p tcp the 2345.
Restart the SSH service to take effect.
Or
How to Use Rsync with Non-Standard Port
You can specify SSH to use rsync communication between the remote and local hosts. Using SSH over a non-standard port, your remote host performs (2232) using native rsync syntax.
The rsync command lists only files at the source by default, with no destination provided.
Now, with the help of the command below, we can copy locally.
‘file1’ is copied into ‘dir1’ with the above command. Also, here the -v option is used for output only.
Rsync SSH to a Specific Port
We can connect to a machine running SSH on a specific port using rsync with the help of the following command.
Change and uncomment the port number. Here, we are changing port number 22 to 2345.
Using the -p option, specify the port on which SSH runs, as specified above. Using rsync+ssh, it copies the file.
The rsync command pushes a local file with a custom SSH port 22. Here, the local SSH port does not matter.
Conclusion
To work with another host, rsync has to use a non-standard port from a security perspective to copy files and back-up data over the default SSH port. In this article, we have seen how rsync is used with non-standard ports. Please feel free to contact us with any questions, problems, or doubts about the above information.