Guide For Changing SSH Port In Red Hat Enterprise Linux

Linux, Linux web server, web hosting

If Security enhanced server or SELinux is enabled on your server, there is a default feature that comes equipped with Red Hat Enterprise Linux.

The Red Hat Enterprise Linux responsible for blocking every port that provides access to SSH, port 22 is an exception that is offered with this capability as default. While working with the Linux web servers, there might be instances when you have to change the SSH Port.

If you would like to utilize any other port, you will have to make some changes to the settings. The steps mentioned below will help you in terms of changing your SSH port in SELinux.

Step 1 : Log in with the Root access

Step 2: Run the following function for checking the settings of the port that you are currently on:

semanage port -l | grep ssh

You will see something similar to the result shown below:

ssh_port_t tcp 22

Step 3: Here, you will have to move ahead with adding your desired port. For doing this, use the command mentioned below:

semanage port -a -t ssh_port_t -p tcp 1234

Note: Replace ‘1234’ with the exact port number as per your preference

Step 4: Run a check in order to ensure that the port mentioned by you added to the

‘acceptable port list’. It done with the following command:

semanage port -l | grep ssh

Once this command executed, you see that the port mentioned by you has been added. Pertaining to the example mentioned above (1234), the result shown like this:

ssh_port_t tcp 1234,22

Step 5 : Restart the OpenSSH utilizing the command mentioned below, so that the changes applied

/sbin/service sshd restart

The process mentioned above will enable you to access SSH through the port preferred by you. It is also important to ensure that the SSH configured properly and the port successfully enabled in the firewall settings.