Changing your SSH port helps improve server security by reducing brute-force login attempts. Hosteons provides a free Bash script that works across multiple Linux distributions and handles all necessary changes including firewall rules and SELinux policies.
Important Disclaimer
Changing the SSH port may make your server inaccessible if something goes wrong. Please make sure you have console access such as VNC, IPMI, or KVM before using this script.
Supported Operating Systems
-
Ubuntu 20.04 and 22.04
-
Debian 11 and above
-
CentOS 7 and 8
-
AlmaLinux 8 and 9
Script Features
-
Prompts until a valid new SSH port is entered
-
Updates sshd_config automatically
-
Opens the new port in firewall (UFW, firewalld, or iptables)
-
Adds SELinux policy rules if SELinux is enabled
-
Restarts SSH service without requiring reboot
How to Use the Script
-
Login to your server via SSH as root
-
Run the following commands:
wget https://raw.githubusercontent.com/hosteons/SSH-Port-Changer-Script/main/ssh_port_changer.sh
chmod +x ssh_port_changer.sh
./ssh_port_changer.sh
-
Enter the new SSH port number when prompted
What the Script Does
-
Backs up your existing SSH config
-
Adds the new port to the correct firewall manager
-
If SELinux is enabled, adds the port context via semanage
-
Restarts the SSH service automatically
GitHub Repository
You can view and download the script from the following link:
https://github.com/hosteons/SSH-Port-Changer-Script
Need Help?
If you need assistance or face any issues, please open a support ticket at:
https://my.hosteons.com