To change the port number that OpenSSH listens on in CentOS Linux 5/6, you will need to edit the OpenSSH server configuration file.
/etc/ssh/sshd_config
file in a text editor.sudo nano /etc/ssh/sshd_config
Port
and change the port number to the desired value. For example, to change the port to 2222:Port 2222
Save and close the sshd_config
file.
Restart the OpenSSH server to apply the changes:
sudo service sshd restart
sudo firewall-cmd --add-port=2222/tcp --permanent sudo firewall-cmd --reload
After completing these steps, the OpenSSH server will listen on the new port number that you specified. You will need to specify the new port number when connecting to the server using an SSH client.
Note: It is generally a good idea to use a non-standard port number for SSH to reduce the risk of automated attacks. However, changing the port number will not provide much security on its own and should be used in combination with other security measures such as strong passwords and SSH key authentication.