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 sever, there is a default feature that comes equipped with Red Hat Enterprise Linux. The Red Hat Enterprise Linux is 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 in the settings. He steps mentioned below will help you in terms of changing your SSH port in SELinux.

Step 1 : Login 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 has been added in the

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

semanage port -l | grep ssh

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

ssh_port_t tcp 1234,22

Step 5 : Restart the OpenSSH utilizing the command mentioned below, so that the changes can be 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 is configured properly and the port is successfully enabled in the firewall settings.

This entry was posted in SSH/RDP and tagged , . Bookmark the permalink.