Many times my colleagues have asked me how to change SSH port on CentOS 7. Obviously, the most straightforward solution (edit /etc/ssh/sshd_config) did not work: OpenSSH failed to restart, something like this:

The reason for “Permission denied” error is that the system has SELinux active, and by default, SELinux only allows port 22 for SSH.

Let us assume that we want SSH to run on port 522, and /etc/ssh/sshd_config has already been modified accordingly.

The first step is to install policycoreutils-python package if it is not installed:

Then, we need to tell SELinux that the SSH daemon is going to use a different port (in our case, this will be 522):

Next, we need to enable access to that port in the firewall (CentOS 7 uses firewalld):

Finally, restart sshd:

Congratulations, SSH daemon is now running on a different port.

CentOS 7: How to Change SSH Port
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *