How to change default SSH port 22 to something else

Internet connected Linux servers are always vulnerable to exploitation by the hackers/intruders. One of their common attack is through SSH. By default SSH servers are configured to listen to port 22 for SSH connection. Changing the port to something else will definitely add an additional measure in securing the server.

How to Change Default SSH port 22 to something else:

  1. Connect to your server via SSH (your ssh port is still 22) as the root user.
  2. Run this command: # vi /etc/ssh/sshd_config
  3. Find out this line: # port 22
  4. Delete the hash “#” sign from the beginning of the line and change the port to something else. Note down this new port very carefully. You’ll need to use this port for the SSH connection from the next login.
  5. Save the file and exit.
  6. Restart the SSH service by executing this command: # service sshd restart 

Now disconnect and try reconnecting with the new SSH port. Make sure you memorize the new port number or note it down somewhere.