Let’s change the SSH port from default 22 to 2222 in CentOS 7.

1. Edit the following file

 

vi /etc/ssh/sshd_config

 

2. Un-coment and Modify the following line

 

Port 2222

 

3. Now by default Selinux is configured to allow SSH port only on 22, to configure if to listen on port 2222 run the following command

 

semanage port -a -t ssh_port_t -p tcp 2222

 

4. Verify the same by running

 

semanage port -l | grep ssh

 

5. Allow Port 2222 in firewall

 

iptables -A INPUT -p tcp --dport 2222 -j ACCEPT

 

6. Restart the SSHD service

 

service sshd restart

 

That’s it, the SSH service is now running on Port 2222