ufw enable or another firewall change, the firewall now blocks your SSH port. Log in through the VNC console in the VPS Panel, allow SSH with sudo ufw allow OpenSSH (Ubuntu/Debian) or sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload (AlmaLinux/Rocky), and connect again. Use your custom port number instead if you changed it.
Before you start
- You need a way in that doesn’t use the network. On a VPS that is the VNC console. On a dedicated server, open a ticket for KVM/IPMI access.
- The console asks for a password. If you only ever used SSH keys, reset the root password first.
- Commands use
sudo. As root, leave it out.
Step 1: Log in on the console
Open the VNC console, click inside it and log in asroot or your sudo user. Use the console’s Clipboard > Type button to paste long commands.
Step 2: Allow SSH again
Find your SSH port first if you aren’t sure:- UFW (Ubuntu / Debian)
- firewalld (AlmaLinux / Rocky)
- iptables / nftables
OpenSSH opens port 22. For a custom port, use sudo ufw allow 2222/tcp.Step 3: Test from a new terminal
Keep the console open and connect from your computer:Step 4: Still locked out? Turn the firewall off temporarily
- UFW
- firewalld
- iptables / nftables
How to avoid locking yourself out next time
- Allow SSH before you enable the firewall. UFW warns
Command may disrupt existing ssh connectionsfor exactly this reason. - Keep your current session open and test in a second one before you log out.
- Test firewalld rules without
--permanentfirst. Runtime-only rules disappear onfirewall-cmd --reloador a reboot, so a reboot from the panel undoes a mistake. - Use
iptables-applyfor iptables rule files. It rolls the change back if you don’t confirm within a timeout. - Write down your SSH port if it isn’t 22.
How to check it worked
sudo firewall-cmd --list-services should include ssh.
Frequently asked questions
Will rebooting the server remove the bad rule?
Not for UFW or saved firewalld rules: they load again at boot. Only runtime-only firewalld rules and unsaved iptables rules disappear.What if I can’t log in on the console either?
Reset the password from the panel and try again. If that doesn’t help, open a ticket and say which firewall command you ran.Does ufw reset help?
It turns UFW off and deletes all rules, so SSH works again. You then have to add every rule again, so prefer ufw allow OpenSSH.
Related guides
VPS and dedicated server guides
Every guide in this section.
Set up UFW
Firewall rules on Ubuntu and Debian.
Set up firewalld
Firewall rules on AlmaLinux and Rocky.
nftables and iptables
Rules without a front end.
VNC console
Your way in when SSH is blocked.
Checked against the official Ubuntu firewall documentation, the firewalld documentation and the iptables-apply manual on 4 November 2026; the UFW warning text (ufw 0.36.2 source), the UFW commands (dry run) and the iptables and nftables commands (in an isolated network namespace) were tested on Ubuntu 24.04 LTS. The firewalld commands were not tested.
Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026