Port number 22 is the default port used by a Linux SSH Server. Changing the port of SSH aids in avoiding automated attacks by offering security to your server.

Security Enhanced Linux or SELinux is a default feature equipped with Red Hat Enterprise Linux. It is responsible to block each port offering access to SSH; port 22 is offered this capability by default.

If you wish to change your SSH port in SELinux, follow the below given steps.

1.Login as Root

2.To check the current settings of the port run semanage. Enter the command:
semanage port -l | grep ssh

The result displayed will be similar to the one given below:
ssh_port_t tcp 22

3.You can proceed with adding the desired port. Use the command:
semanage port -a -t ssh_port_t -p tcp 1234

Note: Replace 1234 with the port number you wish to add

4.Run the below mentioned command to ensure that the port has been added to acceptable port list:
semanage port -l | grep ssh

Post executing the command, you will find that the port has been added:
ssh_port_t tcp 1234,22

5.Use the below given command to restart SSH for changes to apply:
/sbin/service sshd restart

Now, you can access SSH via. your desired port. You need to ensure SSH is configured and port is enabled in the firewall as well.






Leave a Reply

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