Changing the SSH Port in CentOS VPS and Dedicated Servers

By -

Changing the SSH port in CentOs VPS and Dedicated Servers is a very simple task. If you want to change the SSH port follow the steps below.

If you have a firewall installed such as ConfigServer (CSF) make sure you open the new port number before you change the ssh port.

1. Login to your server as the root user.

nano /etc/ssh/sshd_config

2. Uncomment the port line. It should like the the following by default.

#Port 22

default-ssh-port

For example, we will change the port to 12345.

Port 12345

ssh-port-change

Hit Crtl + O to save the file and Crtl + X to close it. Once you have saved the file you can run this command to set the new port in the iptables.
Note: Make sure you make changes to the port number so it reflects the actual port number you used.

ssh-enter-port-iptables

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 12345 -j ACCEPT

After that is done, you need to restart the ssh server. You can do that by entering the following command.

ssh-service-restart

service sshd restart

Or you can enter this command and get the same result.

ssh-restart-service

/etc/init.d/sshd restart

That is all!

iNet Resource

Leave a Reply

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