Changing SSH port on CentOS 7

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

Normally, one adds or changes a SSH port by changing "Port" in /etc/ssh/sshd_config:

#Port 22
Port 26271

On Centos 7 however, this won't work, and sshd will exit when restarted with the following in /var/log/secure:

sshd[4713]: error: Bind to port 26271 on 111.222.111.222 failed: Permission denied.


This is because of SELinux restrictions.


To allow a different SSH port in SELinux, do:

semanage port -a -t ssh_port_t -p tcp 26271


If you're getting "bash: semanage: command not found" error, you have to install an additional package with it:

yum install policycoreutils-python