sudo is broken — "syntax error in /etc/sudoers" and no way back in
A bad edit to sudoers locks out every route to root that depends on sudo — which, on most modern installs, is all of them.
What you see
Every sudo command fails with a parse error, or reports that the user may not run sudo. The root account may have no password set at all.
What is actually wrong
Editing /etc/sudoers with a plain editor rather than visudo, a file in sudoers.d with wrong permissions, or a syntax error in an included file.
Codes and articles
Fixes (2)
Repair it from the session you still have
You still have root somewhere. Do not close that session.
Do not close the session. It is the only route in.
This is worth stating first because the instinctive response — closing the terminal and opening a new one to test — is what turns a five-minute fix into a trip to the console.
Check what is wrong.
visudo -cFix the named file with visudo, which refuses to save a file that does not parse.
visudovisudo -f /etc/sudoers.d/90-custom
Check the permissions, which sudo enforces strictly and which cause a refusal with no syntax error at all.
ls -l /etc/sudoers /etc/sudoers.d/chmod 440 /etc/sudoerschmod 440 /etc/sudoers.d/*chown root:root /etc/sudoers /etc/sudoers.d/*
Note that files in sudoers.d with a dot or a tilde in the name are ignored entirely — a file saved as 90-custom.bak is silently skipped, which is often the actual cause.
Test from a second terminal before closing the first.
sudo -l
visudo -c && sudo -v && echo okRecover from the console
No root session anywhere.
Reboot and interrupt the boot loader. At the GRUB menu, press e on the default entry.
Add init=/bin/bash to the end of the linux line, then boot with Ctrl-X.
linux /vmlinuz-... root=/dev/mapper/vg0-root ro init=/bin/bashThis starts a root shell in place of init, before any service or authentication runs. It requires console access, which is precisely why physical and console access must be treated as equivalent to root.
Remount the root filesystem writable.
mount -o remount,rw /Fix the file, then verify before rebooting.
visudo -cchmod 440 /etc/sudoers
Reboot cleanly.
exec /sbin/initOn a cloud instance where the console cannot do this, attach the volume to another instance, repair the file there, and reattach.
sudo -v && echo okWhere this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.