How to? Change SSH port in CentOS…
The default port to access using SSH is port 22. This default port can be changed in Linux to any custom port not used by other applications.
vim /etc/ssh/sshd_config
Open SSH configuration file using the above command and locate the line where port is updated as #Port 22
Uncomment the line by removing “#” from the beginning and update the customer port value here, I have updated my custom port as 2244…
Press “Esc” then enter “:qw” to save your changes and close file
Allow new SSH port on SELinux
The default port allowed for SSH port is 22, Since, We have recently updated the port to 2244, the same need to be updated here as well.
To allow sshd bind to new updated port, we need to modify the port type here ssh_port_t.
semanage port -l | grep ssh
ssh_port_t tcp 22
semanage port -a -t ssh_port_t -p tcp 2244
Once the port has been modified confirm if the port has been allowed successfully for ssh.
Enable SSH port on Firewall
Once port is configured in sshd, its time to allow the custom port in firewall.
firewall-cmd --add-port=2244/tcp --permanent
firewall-cmd --reload
Restart SSHD service
Now, for the final step, restart ssh service for the changes to take place
systemctl restart sshd
The PORT is successfully changed to custom port…