How to Change Port of SSH Server on AlmaLinux 8

a) Configuring The OpenSSH Server

You can specify any port from 1024 to 65535. Here, we will use 26170 as the port for SSH instead of the default port 22. Edit the /etc/ssh/sshd_config file on your favorite text editor with superuser privileges and add or modify the following line.
Port 26170

b) Adding The Port To SELinux Policy Configuration

You should add the port to the policy configuration of the SELinux (Security Enhanced Linux).
sudo semanage port -a -t ssh_port_t -p tcp 26170

c) Letting FirewallD To Know

Remove the default port of SSH from the firewalld‘s allow list. Removing the ssh service from the list would do so.
sudo firewall-cmd --permanent --remove-service=ssh
You may have to add the new port to the firewalld‘s allow list.
sudo firewall-cmd --permanent --add-port=26170/tcp
Then reload the firewalld.
sudo firewall-cmd --reload

b) Restarting The OpenSSH Server

After all, restart sshd service.
sudo systemctl restart sshd.service
It should give the SSH server a graceful restart.


Documentation

Abdullah As-Sadeed
Abdullah As-Sadeed

Prefers coding from scratch. Loves the Linux kernel.

Leave a Reply