π ~1 min read
Table of contents
Symptom & Impact
Remote SSH access fails after firewall changes, risking admin lockout.
Environment & Reproduction
Usually after enabling UFW with deny defaults.
sudo ufw status verbose
ss -lntp | grep :22
ssh -v localhost
Root Cause Analysis
SSH allow rule missing, wrong interface scope, or rule order conflict.
Quick Triage
Review active policy and numbered rules.
sudo ufw status numbered
sudo iptables -S | head -n 80
sudo journalctl -u ufw -n 80 --no-pager
Step-by-Step Diagnosis
Confirm daemon listens and packet path reaches host.
sudo systemctl status ssh
ip -br a
sudo tcpdump -ni any port 22 -c 20

Solution – Primary Fix
Insert explicit SSH allow rule before restrictive entries.
Still having issues? Our IT Consulting team can diagnose and resolve this for you. Get in touch for a free consultation.
sudo ufw allow 22/tcp
sudo ufw reload
sudo ufw status numbered

Solution – Alternative Approaches
Allow from admin CIDR only for tighter control.
sudo ufw delete allow 22/tcp
sudo ufw allow from 203.0.113.0/24 to any port 22 proto tcp
sudo ufw status
Verification & Acceptance Criteria
SSH connects locally and from remote network.
ssh -o ConnectTimeout=5 localhost true
ss -lntp | grep :22
sudo ufw status verbose
Rollback Plan
Temporarily disable UFW from console if remote lockout persists.
sudo ufw disable
sudo systemctl restart ssh
sudo ufw enable
Prevention & Hardening
Always add SSH allow rule before enabling firewall defaults.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
Related Errors & Cross-Refs
May coincide with cloud ACL or security group misconfiguration.
Related tutorial: View the step-by-step tutorial for Ubuntu 24.04 LTS.
View all Ubuntu 24.04 LTS tutorials on the Tutorials Hub β
Browse all common problems & solutions on the Tutorials Hub.
References & Further Reading
Ubuntu UFW and OpenSSH hardening documentation.
Need Expert Help?
If you cannot resolve this yourself, our team offers hands-on Server Management, Managed IT Services, and flexible Support Plans. Contact us today β we respond within one business day.