Change Default SSH Port

Changing the default SSH port from port 22 to a non-standard port is usually done for security purposes. Hackers tend to scan servers with port 22 opened, then attempt to brute-force their way into the server.

 

While this article is written for Debian/Ubuntu and RedHat/CentOS, the steps are the same for most Linux distributions.


 Change Default SSH port

1

Log in into your server via SSH.

2

Edit the file /etc/ssh/sshd_config with your preferred text editor.

#vi /etc/ssh/sshd_config

3

Change the default port from 22 to your preferred port, e.g. 2222 in the line with the Port number. Highlighted below:

 

Debian:

RedHat:

Uncomment the '#'.

Once complete, save and exit the file.

4

Restart the SSH service.

 

# /etc/init.d/ssh restart

 

Make certain any local iptables or firewalls configured have this new port opened for connection. 

Was this article helpful?
0 out of 0 found this helpful

Have more questions? Contact our support instantly via Live Chat