change ssh port on CentOS 7

  1. Edit /etc/ssh/sshd_config
$ nano /etc/ssh/sshd_config

Look for:
#Port 22

Change to any port number of your choice, for example, 1234
Port 1234

(remove # from the beginning and change 22 to 1234, make sure not to use a port number that’s already used by another service like 80,21,443,53,25 etc..)

2) Add the port number to the firewall on centos 7 then reload the firewall

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

3) Restart SSH :

$ systemctl restart sshd.service