HOW TO: Change SSH Port Number

By Craig | Category: How To

CentOS, Fedora and FreeBSD by default have the port set to 22, to log in over SSH. Here’s how to change that port.

Firstly, edit the SSH configuration file to enable this:

vi /etc/ssh/sshd_config

Find the line:

#Port 22

and change it to:

Port 2222 (Or a port of your choice, make sure it doesn’t overlap with any other ports in use on this machine!)

You need to remove the hash ‘#’ from the start of the line (uncomment the line) and then change ‘22’ to a port of your choosing, save the file and then restart SSH:

/etc/rc.d/sshd restart

You should now be able to log-in over SSH on your desired port number! Be sure to update any firewall configurations to reflect this change, or you may get locked out!

Be the first to write a comment.

Your feedback

You must be logged in to post a comment.