Sudo not working — user not authorized for sudo
sudo: <user> is not in the sudoers file. This incident will be reported.
Focused incident mode — strips away everything but this runbook.
Symptoms
- sudo: <user> is not in the sudoers file. This incident will be reported.
- User cannot run privileged commands
- Password prompt appears but authentication fails even with correct password
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
User sudo access
sudo -l -U <user>Sudoers file contents
cat /etc/sudoers | grep <user> || cat /etc/sudoers.d/<user>
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- sudo -l returns 'not in the sudoers file'
- grep finds no entry for the user or their group
Confirm before fixing
sudo -l -U <user>Confirm no sudo access
Fix
usermod -aG sudo <user>Add the user to the sudo group (Debian/Ubuntu)
echo '<user> ALL=(ALL) ALL' | sudo tee /etc/sudoers.d/<user>Create a drop-in file for the user
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
sudo -l -U <user>Check current sudo privileges
grep -r '<user>' /etc/sudoers /etc/sudoers.d/ 2>/dev/nullSearch for the user in sudoers files
visudo -cf /etc/sudoersValidate sudoers syntax
usermod -aG sudo <user>Add the user to the sudo group
Prevention
- Use /etc/sudoers.d/ drop-in files instead of editing /etc/sudoers directly.
- Always validate with visudo -cf before saving changes to sudoers.
- Use Ansible/Puppet to manage sudoers entries consistently across hosts.
- Limit NOPASSWD to specific commands instead of ALL.
Related runbooks
Same stack, same failure family — worth a skim.
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.