Howtos / Articles

How To Change The SSH Server Port Number

Changing the port number that your SSH server listens on is a simple way to prevent random brute force login attacks against your server. While people can still perform attacks against SSH running on a different port number, most automated tools will default to port 22, and not actually do a full port scan.

Any port number can be used, as long as it is not already in use by another service.

Note: Make sure you are logged in as a user with root privledges when running these commands.

Open the /etc/ssh/sshd_config file in your favorite editor.

# vi /etc/ssh/sshd_config

Look for the following line (it may be commented out, as port 22 is the default):

Port 22


#Port 22

Edit this line to reflect the port number you wish to listen on. Un-comment it if it was commented out:

Port 22843

This will set up the SSH server to listen on port 22843.

Save the file and exit the editor.

Restart the SSH daemon:


$ sudo service ssh restart


# service sshd restart


# service sshd restart

Confirm that it is listening on the new port number by issuing the following command:

netstat -an | grep LISTEN

Make sure that next time you connect, you specify the new port number.

Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>