Change the default SSH port 22

Change the default SSH port 22

The Secure Shell (ssh) protocol by default uses the port 22. Attackers mostly uses the port 22 in automated attack and changing the default will prevent your server from these automated attack. There are many ways of making your server secure and changing the default ssh port is one of the server hardening.

Steps to change the Default SSH port:

1. The first step is log into your server as root user:

ssh root@IPaddress

IPaddress should be replaced with the server’s IP address.

2. Open the ssh configuration in your favorite text editor.

vi /etc/ssh/sshd_config

3. Change the line in the configuration which states “Port 22”. Change the port to any number which is not currently used on the server.

“#Port 22″ should be changed to spmething else such as “Port 2298″

After making the adjustment in the file save and exit from the file.

4. To reflect the changes restart the ssh service.

/etc/init.d/ssh restart

5. Now next step is to allow the port with the server firewall. If you are using CSF then click ‘How to allow the port in CSF‘ and If you are using APF firewall please check ‘How to allow the port in APF’. If none of the firewall is installed then you need to allow the port using IPTABLES:

iptables -I INPUT -p tcp --dport 2298 -j ACCEPT

6. Now verify the ssh connectivity by opening a new session. Keep your current session open, in case, if you need to revert the changes or anything went wrong.

ssh root@IPaddress -p2298