Keep the current SSH session open. Confirm provider-console or physical recovery access, identify the SSH port you actually use, verify its allow rule, and open a second SSH session successfully. Only then remove the smallest faulty rule.
Use the smallest-change sequence
- Record the current state.
Runsudo ufw status verboseandsudo ufw status numbered. Save the output. Also record the SSH port and source IP or management-network CIDR from your known working connection; do not assume port 22. - Confirm a recovery path.
Open the cloud provider’s serial/web console or confirm physical access before changing rules. If no independent recovery path exists, stop. - Preview and preserve the existing SSH path.
Replace both placeholders with values from the connection you already use:sudo ufw --dry-run allow proto tcp from <MANAGEMENT_IP_OR_CIDR> to any port <SSH_PORT>. If the preview is correct, run it again without--dry-run. Do not broaden a previously restricted management path to every source address. - Verify the installed rule and a new connection.
Runsudo ufw status numberedand confirm the source range and destination port. Keep the first session open and connect from a second terminal on that permitted path. A dry run is not a connectivity test. Do not continue until the second session succeeds. - Delete only the faulty rule.
Prefer deleting by the original rule syntax when you need matching IPv4 and IPv6 rules removed together. If you delete by number, only that selected entry is removed; runsudo ufw status numberedagain after every deletion because the numbers change. - Test after each change.
Open another new SSH connection and check the affected service before making the next edit.
Treat reset as recovery work, not cleanup
The Ubuntu Jammy UFW manual states that ufw reset disables UFW and resets it to installation defaults. On a remote server, use it only from an independent console with a written rebuild sequence. Re-add the verified SSH allow rule before enabling UFW, then test from a separate session.
Sources and limits
- Current Ubuntu Server documentation — Firewall, checked 13 Aug 2026.
- Ubuntu 22.04 Jammy manual page — ufw, checked 13 Aug 2026.
The status, numbered-rule, delete, allow, and dry-run patterns are covered by current Ubuntu Server documentation. Reset and dual-stack cautions are scoped to the Jammy UFW manual. Cloud firewalls, nftables rules, containers, and customized SSH configurations can change the result. No live-server test was performed.
Tell us what failed, including your operating system or app version. We review corrections against current primary sources.