How to change the default SSH port in Linux

SSH or the Secure SHell daemon typically operates over port 22 TCP. However, you might want to change the default port for your Linux server, in order to achieve security through obscurity because the standard port is continuously targeted by bots.

To change the default port in Linux, edit the sshd_config file

sudo nano /etc/ssh/sshd_config

Locate the following line # Port 22 , remove the #  and change 22 to the new port number.

SSH Default Port sshd_config
SSH Default Port sshd_config

Save the file and restart the sshd service by running sudo service sshd restart or /etc/init.d/sshd restart .

You can confirm that the SSH service is listening on the new port with the sudo ss -tlpn | grep ssh command.

Don’t forget to update any firewall rules too in order to allow connections to the new port.

 

 

You May Also Like