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.
Most Linux distributions use OpenSSH as the default application as an SSH server. It encrypts all traffic throughout the route and provides a higher level of security. This article describes you to change the OpenSSH server port on a Linux system.
Change SSH Port in Linux
Changing 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 SSH port in Linux, edit OpenSSH configuration file:
sudo nano /etc/ssh/sshd_config
- Change from – Search for the below line, default it can be commented.
- Change to – Remove ‘#’ symbol from prefix to uncomment above line, Then replace 22 with a non-standard port like:
To save and close 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 [email protected]
The rsync user follow these instructions to connect remote system on a different port.
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.