"<User> is not in the sudoers file. This incident will be reported."

Your account lacks sudo rights (or lost them). The fix requires root access from somewhere — console, another admin, or recovery mode. Then it's one line in sudoers, correctly.

What you'll see

Root causes

User not in sudo/wheel group (or group removed from sudoers)

Check membership from a working session: id -nG. Some distros require wheel with an explicit %wheel ALL=(ALL:ALL) ALL line in /etc/sudoers.

A broken sudoers edit locked everyone out

Editing /etc/sudoers directly (not via visudo) with a syntax error can nuke all sudo. That's why every guide says visudo.

Fix it

  1. Gain root out-of-band (console, another admin, recovery)
    # cloud provider serial console, or: reboot into single-user/recovery mode, or: su - from an admin session
  2. Add your user to the right group
    usermod -aG sudo <user>   # debian/ubuntu ; usermod -aG wheel <user>   # rhel/fedora/arch
  3. Or add an explicit sudoers drop-in (the clean way)
    echo '<user> ALL=(ALL:ALL) ALL' | EDITOR='tee' visudo -f /etc/sudoers.d/<user>   # validated on save
  4. Verify from a fresh session
    sudo -v && sudo whoami   # expect root

Field note

visudo validates syntax before saving — a bad line is rejected, not silently breaking sudo. Passwordless ALL for convenience: '<user> ALL=(ALL) NOPASSWD:ALL' is standard for automation but a real security trade — scope it to specific commands when possible.

Common questions

Can I add myself to sudo without root?

No — sudoers changes require root by design. That's the point of the file. Use a provider console, recovery mode, or another admin account.

Why did sudo break for everyone after my last edit?

A direct /etc/sudoers edit with a syntax error makes sudo refuse to run for all users (fail-closed). Boot to recovery, run visudo -c to find the bad line, and fix it there.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.