Changing the default SSH port on CentOS 7

Step 1: To change the default SSH port, the first thing you want to do is backup the current SSH configuration on your system. To do that, run the commands below.

#cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

Step 2: Next, run the commands below to open the default SSH configuration file

Step 3: When the file opens, make the below change and save the file. Un-comment or remove the (#) before the line the reads Port and change the port number you want to use.

Ex: Port 3306

Step 4: After that, run the commands below to allow the new port through the firewall.

# firewall-cmd –permanent –zone=public –add-port=3306/tcp

Step 5: Reload the firewall configurations

# firewall-cmd –reload

Step 6: Restart SSH by running the commands below.

# systemctl restart sshd.service

Step 7: Verify that SSH is now running on the new port by running the commands below.

# netstat -tuplen | grep -i ssh