Enabled UFW and Now I Can’t SSH

It was a rookie mistake. UFW disables all incoming traffic, including SSH (port 22), by default.

UFW (Uncomplicated Firewall) is a frontend for iptables, designed to manage your host-based firewall. It just simplifies updating your firewall configuration on Debian-based machines.

If you are connected via SSH when you enabled UFW, your existing connection will stay intact. However, as soon as you disconnect and try to reconnect, you won’t be able to. To avoid this, you should enable SSH access before enabling UFW, or you will need terminal access to the machine to allow port 22

To allow SSH traffic with UFW, run one of the following commands:
sudo ufw allow ssh
sudo ufw allow 22

If you need to disable UFW to regain access, use:
sudo ufw disable

Nowadays, UFW provides a warning indicating that enabling it will interrupt your SSH connection. Pay attention to these warnings to avoid locking yourself out of your system.

ufw warning

Learn more about UFW here

Leave a Comment

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

Scroll to Top