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.
Learn more about UFW here