Linux Error: 'is not in the sudoers file. This incident will be reported.' — Cause, Fix, and Troubleshooting Guide
Fix the Linux 'deploy is not in the sudoers file. This incident will be reported.' error: add the user to sudo/wheel, repair /etc/sudoers with visudo, recover when locked out.
- #linux
- #troubleshooting
- #permissions
- #sudo
Stuck on this Linux Admins error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
What this error means
You run a command with sudo and instead of a password prompt you get a curt refusal:
deploy is not in the sudoers file. This incident will be reported.
This comes from the sudo security policy plugin (sudoers). It means sudo consulted /etc/sudoers and every drop-in under /etc/sudoers.d/, found no rule matching your user, host, and command, and refused. The alarming “This incident will be reported” line is just the default sudo lecture — it writes the denied attempt to the auth journal. It is not evidence of an attack, and there is no remote “report” being filed.
The usual root cause is mundane: the account is not in the privilege group (sudo on Debian/Ubuntu, wheel on RHEL/Fedora), or a hand-edited sudoers file is broken and silently ignored.
How it manifests on the host
sudo <cmd>prints<user> is not in the sudoers file. This incident will be reported.and exits without running the command.- The user can log in normally over SSH but cannot escalate to root.
sudo -lreportsSorry, user deploy may not run sudo on <host>.- The failure started right after a host cleanup, a group change, or an edit to
/etc/sudoers. journalctl -t sudoshows lines likedeploy : user NOT in sudoers.
System configuration causes
- Not in the privilege group. The user was never added to, or was removed from,
sudo(Debian/Ubuntu) orwheel(RHEL/Fedora), so the group-based rule no longer matches. - A broken
/etc/sudoersor drop-in. A file was edited by hand (not withvisudo) and now has a syntax error.sudorefuses to load a malformed sudoers tree and falls back to “no rules,” denying everyone. - Missing
@includedirline. Someone edited/etc/sudoersdirectly and dropped the@includedir /etc/sudoers.d(older:#includedir) directive, so every drop-in rule is ignored. - Wrong mode/owner on a drop-in.
sudosilently skips any file in/etc/sudoers.d/that is not0440androot:root, or whose name contains a.or~. - Stale group session. The user was just added to
sudo/wheelbut has not started a new login session, so the current shell still lacks the group.
Interrogating the host
Run these read-only checks first — they change nothing.
-
Confirm what
sudobelieves the user may do:sudo -l -U deploynot allowed to run sudomeans no rule matches — a group or rule problem, not a password problem. -
Check group membership:
id deploy getent group sudo wheelIf
deployis not listed insudo(Debian/Ubuntu) orwheel(RHEL/Fedora), the group rule cannot apply. -
Validate the entire sudoers tree parses cleanly:
sudo visudo -cAny file it flags as bad is being ignored in full.
-
Inspect the drop-ins and the include directive:
ls -l /etc/sudoers.d/ sudo grep -E 'includedir|@include' /etc/sudoersFiles must be
-r--r----- root root(0440), and the@includedir /etc/sudoers.dline must be present. -
Read the denied attempts:
sudo journalctl -t sudo --since '15 min ago'
Remediation
Important: always keep a second root shell open (or console/out-of-band access ready) while changing sudo policy, so a mistake cannot lock you out.
-
Add the user to the privilege group from any working root or sudo session:
sudo usermod -aG sudo deploy # Debian/Ubuntu sudo usermod -aG wheel deploy # RHEL/Fedora/RockyThe user must log out and back in for the new group to take effect (
idin a fresh shell confirms it). -
Repair a broken sudoers file — only with
visudo, never a plain editor.visudorefuses to save syntactically invalid content:sudo visudo # edits /etc/sudoers safely sudo visudo -f /etc/sudoers.d/deploy # edits a specific drop-in safelyRestore the include line if it was lost:
@includedir /etc/sudoers.d -
Fix drop-in permissions so
sudowill load the file:sudo chown root:root /etc/sudoers.d/deploy sudo chmod 0440 /etc/sudoers.d/deploy -
Grant a scoped rule (preferred over blanket access) via a validated drop-in:
echo 'deploy ALL=(ALL) /usr/bin/systemctl' | sudo visudo -cf - # validate first echo 'deploy ALL=(ALL) /usr/bin/systemctl' | sudo tee /etc/sudoers.d/deploy sudo chmod 0440 /etc/sudoers.d/deploy -
Recover when you are fully locked out (no working sudo/root shell):
- Console as root. Log in directly as
rooton the physical/virtual console (if root login is enabled) and run theusermod/visudofixes above. - Single-user / recovery mode. Reboot, select the recovery entry in GRUB, and the shell there is root — remount read-write with
mount -o remount,rw /if needed, then fix the group or sudoers file. pkexec(PolicyKit) can sometimes run a command as root whensudois broken:pkexec usermod -aG sudo deploy- Cloud instances: attach the root volume to a rescue instance, or use the provider’s serial console / user-data to reset access.
- Console as root. Log in directly as
Hardening the host
- The “This incident will be reported” line is the default
sudolecture, not an alert to anyone. Do not treat it as a security event. - Group changes apply only to new login sessions — always re-login (or run
newgrp sudo) before re-testing. - A single bad drop-in disables the whole sudoers tree, not just that file. If one user loses sudo, check
visudo -cbefore assuming it is user-specific. - Editing
/etc/sudoerswithvi/nanodirectly is how most lockouts happen. Usevisudo(orvisudo -f) every time — it is the syntax gate. - On RHEL/Fedora the group is
wheel, on Debian/Ubuntu it issudo. Adding a user to the wrong group looks correct inidbut never matches the rule.
Related system errors
- Linux Error: Operation not permitted
- Security Error: user is not in the sudoers file (privilege escalation / hardening angle)
- Linux Error: Host key verification failed
Want faster Linux incident response? Use DevOps AI Toolkit to turn production errors into clear diagnostics, remediation steps, and reusable runbooks.
Fixed it? Get 500 Linux Admins & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Did this fix your issue?
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.