Locked Out of SSH: Fixing a Bad AllowUsers Directive

Updated 2026-11-01

You SSH in, the connection is accepted, then instantly closed — no password prompt, no key challenge. A frequent culprit is an AllowUsers (or AllowGroups/DenyUsers) directive in sshd_config that no longer lists the accounts you actually log in as.

Read the auth log

# on the server (console/out-of-band access):
tail /var/log/auth.log       # or journalctl -u ssh
# "User admin not allowed because not listed in AllowUsers"

Fix it without a second lockout

Edit /etc/ssh/sshd_config so the directive lists the right accounts, validate the config, and reload rather than restart so existing sessions survive if you got something wrong:

AllowUsers admin deploy

sshd -t                      # validate config syntax first
systemctl reload sshd        # apply; keep a second session open as a safety net

Always keep one SSH session open while changing sshd_config — if the change locks you out, you can revert from the session you still have. For a replaced-host-key error instead, that's a different problem (client-side known_hosts).

Practise it

SSH lockouts are one of the simulator's access incidents. Work them in a full incident response shift.

Learn it by doing

Create a free account and practise on a live fleet.

← All guides