I always forget the exact commands to change the port ssh (or any default service in the case of the selinux bits) runs on. It’s nicely simple though!
Edit /etc/ssh/sshd_config to change the port number:
Port 2022
You can add a second line if you wish to initially leave it running on Port 22 too in case something goes wrong, obviously don’t forget to remove it once the new port is working!
To add port 2022 to port contexts, enter:
# semanage port -a -t ssh_port_t -p tcp 2022
You can verify new settings, enter:
# semanage port -l | grep ssh
Sample outputs:
ssh_port_t tcp 2022,22
Reload the sshd service to pick up the new config:
#systemctl reload sshd.service
And of course don’t forget to update your firewall to allow the new port through.
Peter Robinson: Changing ssh ports on Fedora or RHEL http://t.co/A6sF1d2bGy
Peter Robinson: Changing ssh ports on Fedora or RHEL http://t.co/duRHIWr6zM
Peter Robinson: Changing ssh ports on Fedora or RHEL http://t.co/gHeZLqkws2
Peter Robinson: Changing ssh ports on Fedora or RHEL http://t.co/UF3nNFYD6r
Promena ssh portova na #Fedora ili RHEL-u http://t.co/chnd9CjuMN
@nullr0ute alternative: dnat in the prerouting chain. Useful if you only want external ssh on a different port.