
Changing your SSH port is a simple yet powerful way to reduce brute-force login attempts and improve server security. To make this process easier, Hosteons offers a free Bash script that automatically handles the switch across all major Linux distributions — including firewalls and SELinux!
✅ Supported Operating Systems
- Ubuntu 20.04 / 22.04
- Debian 11 and above
- CentOS 7 / 8
- AlmaLinux 8 / 9
⚠️ Important Disclaimer
Changing your SSH port can lock you out if anything goes wrong.
Make sure you have console access such as VNC, IPMI, or KVM before using this script.
🔧 What the Script Does
- Prompts until a valid SSH port is provided
- Edits /etc/ssh/sshd_config to set the new port
- Adds firewall rules for:
- UFW (Ubuntu/Debian)
- firewalld or iptables (CentOS/AlmaLinux)
- Handles SELinux with semanage if needed
- Restarts SSH service safely without reboot
🧰 How to Use the Script
- SSH into your VPS or server 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 your desired new SSH port when prompted
📦 Download from GitHub
Access the script and full documentation here:
👉 https://github.com/hosteons/SSH-Port-Changer-Script