The platform enforces one rule on your machine — anti-spoof, which lets it emit only from its own IP and MAC — and filters nothing else. There is no firewall API; the policy is yours. **A rule that drops your own SSH is permanent**: there is no console and no password (access).
Apply firewall and sshd changes behind a dead-man switch: schedule the revert *first*, confirm you still have access, then cancel the revert.
# 1. schedule the undo before you change anything
systemd-run --on-active=10min --unit=fw-revert nft flush ruleset
# 2. apply your ruleset
nft -f /etc/nftables.conf
# 3. from somewhere else, open a SECOND ssh session and confirm it works
# 4. only then, cancel the undo
systemctl stop fw-revert.timer
If step 3 fails, do nothing: the timer fires and the machine lets you back in.
The same shape works for ufw (systemd-run --on-active=10min ufw disable)
and for sshd — restart it, then prove a *new* session connects while the old
one is still open, because the session you are holding survives a restart that
broke the config.
Take a snapshot before anything structural: the only other undo. It bills for as long as you keep it, and rolling back needs the VM stopped and leaves it stopped.
Key-only is already the case, so the useful changes are small:
PermitRootLogin no. Log in as ubuntu and use sudo.PasswordAuthentication no and KbdInteractiveAuthentication no, so a
future image change cannot quietly turn one on.Run sshd -t before restarting: it refuses to start on a config it cannot
parse, and an sshd that will not start is a machine you cannot enter.
:25 is blocked upstream of your VM, so no in-guest
configuration reopens it. Mail goes through the
relay.Details of both: Firewall.
Already locked out: [Debug a VM that will not come up](debug-vm-boot.md#5-if-it-is-the-guest-it-is-unrecoverable).