RHEL 6: Change OpenSSH Port To 1255 ( SELinux Config )

To change the OpenSSH port on Red Hat Enterprise Linux 6 (RHEL 6) with SELinux enabled, you need to perform the following steps:

  1. Edit the OpenSSH configuration file:
sudo vi /etc/ssh/sshd_config
  1. Find the line that starts with Port and change it to the desired port number. In this case, you want to change it to 1255, so the line should look like this:
Port 1255
  1. Save the changes and exit the file.
  2. Restart the OpenSSH service to apply the changes:
sudo service ssh restart
  1. Update the SELinux policy to allow the new port:
sudo semanage port -a -t ssh_port_t -p tcp 1255
  1. Verify the change by attempting to connect to the new port with the ssh command:
ssh localhost -p 1255

Note: Make sure that the firewall on your system is configured to allow incoming connections on the new port (1255). If you have the iptables firewall, you can add the following rule to allow incoming connections on port 1255:

sudo iptables -I INPUT -p tcp --dport 1255 -j ACCEPT

Also, be aware that changing the default OpenSSH port may increase your system’s security, but it will also make it more difficult for you to connect to the system using standard tools. Make sure to properly document the change so that you don’t forget the new port number.

Leave a Comment