How to Change Your SSH Port Safely on Any Linux Server (Ubuntu, Debian, CentOS, AlmaLinux)

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

  1. SSH into your VPS or server as root
  2. 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
  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.