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


Log in into your server via SSH.


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

#vi /etc/ssh/sshd_config


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




Uncomment the '#'.

Once complete, save and exit the file.


Restart the SSH service.


# /etc/init.d/ssh restart


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