Please come back for more

How To Change SSH server port

 

If you want to change the ssh server port for any reason namely security (extremely recommended), From the default port which is 22 .You can use any other port but above 1024 is preferable.

To change the port on the server, First make a copy :

cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.orig.$(date +%F)

Then change the port to … for example 2222 :

nano /etc/ssh/sshd_config

Unmark the #port 22  to  port 2222

Also allow it through the SElinux :

semanage port -a -t ssh_port_t -p tcp 2222

Note: if you get “semanage command unknown” you should install the tool with YUM, this will add the option :

yum install policycoreutils-python

Now add the port to the firewall rules:

firewall-cmd --zone=public --add-port=2222/tcp --permanent

List all rules to make sure you did good :

firewall-cmd --list-all

Reload the firewall to apply the rules:

firewall-cmd --reload

Restart SSH to apply the changes:

systemctl restart sshd

 


Good Luck

Leave a Reply

Your email address will not be published. Required fields are marked *