To change your SSH port on CentOS you can first edit the sshd_config file located in /etc/ssh/sshd_config.
Once you open that up the port line should be commented out and look something like this:
So you can uncomment it and set it to whatever port you’d like…I’ll use 2222 in this example.
Once you do that go ahead and save it by hitting CTRL+O and enter, then CTRL+X to exit nano. Now we need to open up the new port in iptables by running these commands:
iptables -I INPUT -p tcp --dport 2222 -j ACCEPT
Now that port 2222 is open and accepting connections, we can go ahead and restart the sshd service.
Once you do this go ahead and open a new terminal or PuTTy session and try to connect to the new port to test that it’s working while leaving your original session open in case it does not. If it doesn’t work please be sure you followed all the instructions carefully because if you close your first session you could get locked out of your server!