How to change ssh port in CentOS 6?

Changing SSH port is a very important security tip and helps  in avoiding bruteforce attacks on server.

By default ssh port is 22 on all the servers, it can be easily changed by editing the ssh configuration files.
Connect normally on ssh from  22 port and We will start with installing text editor nano.

$ yum install nano -y

and now we will edit the config of ssh.

$ nano /etc/ssh/sshd_config

After running the last command you will be taken to the nano editor where you will have  to find this line and uncomment.

Change “#Port 22” to  “Port 22” by removing # and change the 22 to the port  number you want it to changed, for eg. “Port 9824”.  Press Ctrl+O to save and press enter again to confirm and then press Ctrl+x to exit nano editor.

After saving we will restart ssh on server.

$ service sshd restart

It will result in successfully changing the ssh port and you will be able to access your server from the port that you put in.

Leave a Reply

Your email address will not be published. Required fields are marked *