Steps to Change SSH Port in Red Hat Enterprise Linux

June 21, 2011 / Security and Backup

Earlier, we have had a look at the Steps to Change SSH Port of a Linux Server from the default port 22 to something of your preference. The steps described therein must have been helpful, but it there weren’t due the fact that you have RHEL 6 installed on the server, then you probably would have encountered an error stating the denial of permissions.

This is because the Security Enhanced Linux or SELinux is enabled over your server. This is basically a default feature which comes equipped with Red Hat Enterprise Linux which is responsible for blocking each port that offers access to SSH, only the port 22 is offered this capability by default.

If you wish to use any other port, few changes in the settings are required.

The following steps would help you change your SSH Port in SELinux

  1. Login as Root
  2. Run semanage to check the settings of the port that you currently. As root, type:
    semanage port -l | grep ssh
    You should be able to see something similar to as shown below :
    ssh_port_t tcp 22
  3. Here, you must proceed with adding your desired port. Use the below command to do so :
    semanage port -a -t ssh_port_t -p tcp 1234
    Note : Replace 1234 with the port number of your preference
  4. Run a quick check using the following command to ensure that the port has been added to acceptable port list :
    semanage port -l | grep ssh
    Upon execution of the command, you should be able to see that the desired port has been added :
    ssh_port_t tcp 1234,22
  5. Restart OpenSSH using the following command for the changes to apply :
    /sbin/service sshd restart

This will allow you to access SSH via. your desired port. You also must ensure that the SSH is well configured and the port is enabled in the firewall settings as well.

You may contact our support department for any assistance with this. You may either raise a ticket via. helpdesk, drop an email to [email protected] or reach via. Live Chat.

We offer round the clock web hosting UK services and take privilege in helping you get the issue resolved at the earliest.

Spread the love