Changing the SSH port
The SSH (Secure Shell) protocol is primarily known for providing secure remote access to servers. However, its versatility extends beyond remote shell access. The SSH protocol can also be utilised for various other purposes, including securely transferring files between machines and creating secured TCP tunnels.
One significant benefit of using SSH for file transfer is the added layer of security it provides. Traditional file transfer methods, such as FTP (File Transfer Protocol), transmit data in clear text, leaving it vulnerable to interception and unauthorised access. In contrast, SSH file transfer ensures that data is encrypted, protecting it from potential threats.
To transfer files using SSH, the protocol employs the SFTP (SSH File Transfer Protocol) subsystem. SFTP enables users to securely upload, download, and manage files on remote systems. It supports various operations, such as file and directory creation, deletion, renaming, and permission management.
In addition to file transfer, SSH can be used to create secured TCP tunnels. This feature, often referred to as SSH tunnelling or port forwarding, allows users to securely relay network traffic between two machines. By encapsulating the traffic within an SSH connection, SSH tunnels provide an additional layer of encryption and authentication.
Step-by-step guide to changing the SSH port
Changing the SSH port is essential for enhancing the security of your server. By following this step-by-step guide, you have effectively made it more difficult for potential attackers to find a way to connect to your server. If you leave the default port value, potential attackers will have an easier time finding a way to connect to your server.
How to change the SSH port
The first thing you need to do once you have successfully logged into your server is to change the ‘/etc/ssh/sshd_config’ file.
IMPORTANT: Please make a backup of this file before making any changes.
Open / / etc / ssh / sshd_config in a text editor (the editor is not important, in this example we use nano)
Comment out the #Port 22 line and change the value to your desired one
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
Next, depending on the firewall running in the system, create a rule that will not deny connections to the new port
For the firewall
# firewall-cmd --reload
Restart the SSH service
To ensure that your changes are applied, you will need to restart SSH. This command will allow you to do so:
When you restart the service, the connection will be broken. Next, when connecting to the server, you must specify the port number, for example
By following these steps, you can easily change the SSH port on your server(s) to enhance its security. By changing the default port from 22 to a custom port number, you make it more difficult for attackers to guess and gain access to your server.
Remember to restart the SSH service after modifying the configuration file to ensure the changes take effect.