Changing SSH port on CentOS 7

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 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