Changing SSH Port on SELinux

Updated:

In this post, I’ll cover how to change the SSH port on SELinux. Normally, SSH configuration can be done with the following commands:

sudo vim /etc/ssh/sshd_config  # Change Port 22 to desired port
sudo firewall-cmd --permanent --add-port=<your_port>/tcp
sudo firewall-cmd --reload

However, on SELinux, port permissions for SSH are managed separately and must be added:

sudo semanage port -l | grep ssh
> ssh_port_t                     tcp      22
sudo semanage port -a -t ssh_port_t -p tcp <port>
sudo semanage port -l | grep ssh
> ssh_port_t                     tcp      <port>, 22

Now restart the service:

sudo systemctl restart sshd