Here’s how to change SSH port on CentOS 7 to increase your server security. Changing the SSH port is one of the important steps to take once your server is deployed.

1. Edit SSH config file with nano or your preferred editor

$ nano /etc/ssh/sshd_config

2. Press CTRL+W to search and then type ‘Port‘ to search for the word Port in the config file

3. Replace #Port 22 with Port 1234 “remove the #” (and replace 1234 with a port number of your choice)

4. Press CTRL+X

5. Press Y and Enter to save the changes

6. Restart SSH 

$ sudo systemctl restart sshd.service

Check if firewalld is running, you’ll need to whitelist the new port number

$ sudo firewall-cmd --state

if the output is ‘running‘ , follow the next steps.

1. Add the custom port to firewalld:

$ sudo firewall-cmd --permanent --zone=public --add-port=1234/tcp

2. Reload the firewall configurations:

$ sudo firewall-cmd --reload

If you’ve another firewall installed like CSF, make sure to open the new SSH port on CSF.