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.
2. Uncomment the port line. It should like the the following by default.
For example, we will change the port to 12345.
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.
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.
service sshd restart
Or you can enter this command and get the same result.
That is all!