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.
Method #1
1. If it's the first time to change the SSH port on this system you can use the following command to change the default SSH port from 22 to 3333 for instance.
sed -i 's/#Port 22/Port 3333/g' /etc/ssh/sshd_config
Replace 3333 with the intended port number.
2. Restart sshd service
systemctl restart sshd.service
Method #2
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 3333 "remove the #
" (replace 3333 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
$ 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=3333/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.