Here's how to change SSH port on Almalinux/RHEL to increase your server security.
Changing the SSH port is one of the important steps to take once your server is deployed.
1. Edit SSH config file with nano or your preferred editor
$ nano /etc/ssh/sshd_config
2. Press CTRL+W
to search and type Port to find the line #Port 22
in the config file
3. Replace #Port 22 with Port 1234 "remove the #
" (and replace 1234 with a port number of your choice)
4. Press CTRL+X
to exit the editor
5. Press Y and Enter to save the changes
6. Restart SSH service
$ sudo systemctl restart sshd.service
Firewall Configuration
Check if firewalld service is running on your system.
firewall-cmd --state
If the output is running
, follow the next steps:
- Add the custom port to firewalld:
firewall-cmd --permanent --add-port=1234/tcp
Note: Replace 1234 with your new port number.
- Reload the firewall configurations:
firewall-cmd --reload
If you've another firewall installed like CSF, make sure to open the new SSH port on CSF.
HostRound Offers premium USA Dedicated Servers and VPS Hosting in the Netherlands and Dallas, TX.