SSH (Secure Shell) is the most popular protocol for connecting remote Linux systems. Changing the SSH port will provide you with an extra layer of security. The new port will be a little harder to identify for hackers.
Change SSH Port in Linux
Changing the SSH port is a straightforward process in Linux systems. Any system can use the port range 1 to 65535, For TCP, port number 0 is reserved and cannot be used. The default SSH service listens on port 22. Just this port with some other ports.
To change the SSH port in Linux, edit the OpenSSH configuration file:
sudo nano /etc/ssh/sshd_config
- Change from – Search for the below line, default it can be commented.#Port 22
- Change to – Remove the ‘#’ symbol from prefix to uncomment above the line, Then replace 22 with a non-standard port like Port 2232
To save and close a file press CTRL + X
keys, then press ‘y’ and hit enter button.
Now, restart the SSH daemon to apply changes.
sudo systemctl restart ssh
That’s it. The SSH service is now running on an updated port as configured above.
Connect SSH to New Port
The SSH service is listening on a non-standard port. So, you have to provide a port number while connecting the server using the ssh client.
Use the following command from the client machine to connect the remote server to a new port.
ssh -p 2232 user@remote-host
Conclusion
This tutorial helped you to secure your Linux server by changing the SSH port to a non-standard port. Once the SSH port is changed, you must update the firewall rules to secure the new port.