Broken sudoers: Recovering from a Syntax Error

Updated 2026-11-01

A single bad line in /etc/sudoers breaks sudo for everyone — >>> /etc/sudoers: syntax error — and if sudo is your only path to root, you've locked yourself out of your own escalation. This is why the golden rule is: never edit sudoers directly.

Always edit with visudo

visudo locks the file against concurrent edits and — crucially — validates the syntax before installing it, so a typo can't take effect. To check a file without editing (e.g. one you deployed via config management):

visudo -c                      # validate the live /etc/sudoers
visudo -cf /etc/sudoers.new    # validate a candidate before installing

If you're already locked out

If sudo is already broken, you need root another way: a root shell you still have open, a console login as root, pkexec, or booting to single-user/rescue. Then fix the offending line and re-validate with visudo -c before you log out — don't close your last root session until sudo works again.

Practise it

A broken sudoers file is one of the simulator's access-control incidents. Drill it in Linux troubleshooting practice.

Learn it by doing

Create a free account and practise on a live fleet.

← All guides