Overview #
In this short tutorial you will learn how to change your SSH port from the default 22 to another port. This is a recommended step during any initial server hardening. Cloudfanatic’s Almalinux 9 comes with SELinux set to enforcing by default and firewalld active.
Changing the SSH Port: #
Edit your ssh configuration file:
nano /etc/ssh/sshd_config
- Find line: #Port 22
- Uncomment the line
- Change 22 to your desired port number
- Save the file
Allow your new SSH port through SELinux #
yum -y install policycoreutils-python-utils
semanage port -a -t ssh_port_t -p tcp 12345
where 12345 is your new SSH Port.
Allow your new SSH port through firewalld #
firewall-cmd --add-port=12345/tcp --permanent
firewall-cmd --reload
Restart SSHd #
systemctl restart sshd
That should be all. Try and ssh into your server on your new port.