How to change SSH default port

Most script kiddies & crackers will first try and telnet to a server to see if Telnet is running. Failing that, they will attempt SSH.

Moving the default SSH port to another port usually stops all brute force attempts immediately.

To change the  default port, do the following:


  1. Login to your VPS via SSH, as usual.
  2. Edit the config file, /etc/ssh/sshd_config
  3. Scroll down to the "Port" enty, and change the "22" to something else - choose something above 1024 (everything below 1024 are registered port numbers and can't be used). To be safe, take a look at /etc/services to see which ports numbers could be in use by other programs, and choose something that won't be used by other programs. For this example I'll choose port 1234.
  4. Save the file, and restart SSH, by running "/etc/init.d/sshd restart"
  5. Now, open a new SSH session, and connect to the newly added port, to see if it works. If not, just go back to #1 and do it again.


Some more tips from the CentOS Wiki: 

P.S. If you're on another Linux server, you can connect to the new port, as follows: ssh {}  -p12345. Change {} with your VPS's real IP address

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How can I set a nice looking bash prompt on my Linux VPS?

Add the following lines to the end of /etc/profile PS1="\[\e]2;\u@\H...

How do I change my VPS's hostname

If you want to change your Virtual Private Server's hostname, you first need to login to your VPS...

What is a Virtual Private Server?

A Virtual Private Server, or VPS is simply put, a "slice" of a dedicated server. Dedicated...

How can I secure my VPS?

If you own, or run a Virtual Private Server, or Dedicated server on the internet, then you need...

how do I disable root logins?

Disabling direct root login to your VPS is almost a must!...