SSH & Remote Administration
Stop getting locked out when you change your SSH port
đź§© The Challenge
You’re hardening a server and decide to move SSH off port 22 to stop the endless stream of botnet login attempts. Ten seconds later, you close the terminal and realize you forgot to open the new port in your firewall or update your local config.
đź’ˇ The Fix
Test your changes by opening a secondary persistent connection before you kill your existing session. This keeps a safety net active so you don’t end up needing a KVM console just to fix a typo.
ssh -p 2222 user@host &
sleep 5
[ -d /proc/$! ] && echo "Connection succeeded" || echo "Connection failed, check your firewall"
⚙️ Why It Works
Running the secondary connection in the background lets you verify the new port is actually reachable while your primary shell stays alive. If that background process dies, you know your firewall rules are still blocking the new port.
🚀 Pro-Tip: Always keep a read-only SSH session open in a separate window when modifying /etc/ssh/sshd_config until you’ve successfully logged in via a fresh terminal.
Linux Tips & Tricks | © ngelinux.com | 9/17/2026
