By default, we connect to GNU/Linux using SSH (or Secure SHell). The main function of this protocol and program is to provide remote access to a server through a secure channel in which all information is encrypted. This connection generally uses TCP port 22.
For greater security, we can change this SSH access port, which is what we will explain in this tutorial.
Change the SSH port
To change the SSH port, edit the SSH configuration file using your preferred editor.
# nano /etc/ssh/sshd_config
Uncomment and modify the following line:
Port 2244
Information
For this example, we have used port 2244, but you can use any other port without any problems. Just make sure you choose a port above 1024, as lower ports are reserved for other common services.
After saving the file, restart the service:
# systemctl restart sshd.service
Then check that SSH is listening on the port you configured:
# netstat -tulpn | grep 2244
tcp 0 0 0.0.0.0:2244 0.0.0.0:* LISTEN 2793/sshd
You should now be able to connect using your chosen port, but keep in mind that you must open the port in your server's Firewall profile to gain access.