⚠️ Warning: This script has been hardly tested. Please proceed with caution.
Changes SSH port on Ubuntu, Debian, or CentOS machine with bash "semi-automatically". Please feel free to use it at your discretion.
User must be root:
sudo -i
Then copy and run:
bash <(curl -Ls https://raw.githubusercontent.com/Eggwite/Change-SSH-Port/main/change_ssh_port.sh)
Optionally, keep old firewall rules:
bash <(curl -Ls https://raw.githubusercontent.com/Eggwite/Change-SSH-Port/main/change_ssh_port.sh) --old-rules
- Ensures the script is compatible with Ubuntu, Debian, or CentOS.
- Allows users to continue with an unsupported version if they choose.
- Retrieves the current SSH port from the
sshd_config
file. - Prompts the user for the current port if it can’t be found.
- Asks the user to enter a new SSH port.
- Check if the new port is available.
- Backs up the current SSH configuration file to
/etc/ssh/sshd_config.bak
.
- Checks if UFW (Uncomplicated Firewall) is installed and updates rules for the new port, removing old port rules.
- Checks if iptables is installed and updates rules for the new port, removing old port rules.
- Optionally keeps old firewall rules if the
--old-rules
flag is provided.
- Modifies the
sshd_config
file to use the new SSH port.
- Restart the SSH service to apply the new configuration.
- If the restart fails, restore the original configuration and restart the service.