About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
When sudo answers alice is not in the sudoers file., the sudoers policy found no entry that names the account or any group it belongs to. A fix that applies when the cause is a missing group is to put the account in the group that sudoers already grants, on Ubuntu the group sudo. Do it from an account that can already administer the server, then check the rules with visudo -c.
What the error means
sudo asks its policy, the sudoers file, whether the invoking user may run the command. The sudoers manual lists the reason for a refusal in its log format: "user NOT in sudoers" means "The user is not listed in the sudoers file." A different reason, "user NOT authorized on host", means the user is listed but not for this host.
The wording after the first sentence depends on the sudo version, and the text comes from sudo's source code, plugins/sudoers/logging.c. At tags SUDO_1_8_31 and SUDO_1_9_5p2 the format is %s is not in the sudoers file. This incident will be reported. At tag SUDO_1_9_16p2 it is %s is not in the sudoers file. followed, only when mail is sent, by This incident has been reported to the administrator. In each, %s is the user name, which is the part that varies. The sudo ChangeLog records that the second sentence was removed on 3 February 2022, because mail to the administrator became configurable and "the warning may not be accurate". Entries dated 21 February 2022 add back a warning, now worded "This incident has been reported to the administrator.", which prints only when the denial is mailed. The ChangeLog entries give no release number. On Ubuntu 25.10 and later the default sudo is a different program, sudo-rs; its wording and behaviour are not covered here.
The mail itself is controlled by the sudoers flag mail_no_user: "If set, mail will be sent to the mailto user if the invoking user is not in the sudoers file. This flag is on by default." The mailto address defaults to root.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| The account is not in the group that sudoers grants | The message appears for this account only | id alice lacks the group; getent group sudo does not list the account |
| The account is in a group, but sudoers grants a different group name | The account is in a group such as admins, yet sudo refuses |
sudo -l -U alice as root lists no privileges; the sudoers file has no rule for that group |
A rule exists in a file under /etc/sudoers.d, but sudo skips the file |
The rule is written down and has no effect | The file name contains a . or ends in ~, or @includedir is missing from /etc/sudoers |
| A syntax error in sudoers | Rules that worked before an edit no longer apply | visudo -c reports the line number of the error |
| The rule names a different user or host | The account is listed, but not for this host | The log reason reads "user NOT authorized on host" instead of "user NOT in sudoers" |
Prove the cause before changing anything
These checks are read-only. Run 2 to 5 as root, or put sudo in front of each command from an account that can already use sudo. If no such account exists, the server needs the console route in "Getting into a Linux server you cannot log in to: rescue targets, rd.break and boot loader passwords".
1. See the groups the account has. The id manual says that with a user name it prints "user and group information", and with no name it prints it "for the current process":
id alice
2. See who is in the group sudoers grants. The Ubuntu documentation says "By default, the initial user created by the Ubuntu installer is a member of the group sudo which is added to the file /etc/sudoers as an authorized sudo user." The getent manual describes group as a database it can read:
getent group sudo
The sudoers manual's own example grants %wheel. Read your /etc/sudoers to see which group name it uses; do not assume.
3. List what sudo thinks the account may do. The sudo manual describes -l with -U as listing "the privileges for user instead of for the invoking user", and, for the sudoers policy, restricts -U to root and to users who have the list privilege for the specified user or who may run any command as root or as that user on the current host:
sudo -l -U alice
4. Validate the whole policy. The visudo manual describes -c as check-only mode: "The existing sudoers file (and any other files it includes) will be checked for syntax errors." It also checks ownership and permissions when no path is given:
visudo -c
5. Check the include directive and the drop-in names. The sudoers manual says @includedir /etc/sudoers.d makes sudo read each file in the directory, and that sudo skips file names that end in a tilde (~) or contain a dot (.):
grep -n includedir /etc/sudoers
ls -l /etc/sudoers.d
Fix
Add the account to the group that sudoers grants
First save the current group data:
id alice > /root/id-alice.2026-11-22
getent group sudo > /root/group-sudo.2026-11-22
Risk: the next command gives alice the full administrator rights that the group sudo carries. The Ubuntu documentation says that to give an account "full root access through sudo", you add it to that group. The command below uses -a with -G on purpose: the usermod manual says that without -a, "If the user is currently a member of a group which is not listed, the user will be removed from the group."
Add the account to the group:
usermod -aG sudo alice
The usermod manual describes -a as "Add the user to the supplementary group(s). Use only with the -G option." Then repeat id alice and getent group sudo, and ask alice to open a new login session and run id.
To undo it, first read /root/id-alice.2026-11-22. Run the next command only if that saved file does not list sudo, because otherwise alice already had that membership and must keep it. Remove the account from the group, then compare with the saved file:
usermod -rG sudo alice
id alice
The usermod manual (shadow-utils 4.19.0) describes -r as "Remove the user from named supplementary group(s). Use only with the -G option." The output of id alice must match /root/id-alice.2026-11-22.
Grant the rights in a drop-in file instead
Use this when the server has no group that sudoers grants, or the account needs narrower rights than full administration. It is only for a file name that does not exist yet. Check first, and stop if a file is shown:
ls -l /etc/sudoers.d/90-alice
First save the current policy files and the directory listing:
cp -p /etc/sudoers /etc/sudoers.2026-11-22
ls -l /etc/sudoers.d > /root/sudoers.d-list.2026-11-22
Risk: the next step edits the sudo policy, and the rule in it gives alice the right to run every command as any user.
Open a new drop-in file with visudo. The sudoers manual says visudo "will not edit the files in a @includedir directory unless one of them contains a syntax error", but that "It is still possible to run visudo with the -f flag to edit the files directly":
visudo -f /etc/sudoers.d/90-alice
Put one line in the file, in the form of the manual's %wheel ALL = (ALL) ALL example:
alice ALL = (ALL) ALL
The file name has no . in it, so sudo does not skip it. Save and exit. visudo parses the file after editing and "will not save the changes if there is a syntax error". Then run visudo -c for the whole policy.
To undo it: if the saved listing does not contain 90-alice, the file is new. Check the exact file first, then remove it with its own command:
ls -l /etc/sudoers.d/90-alice
rm /etc/sudoers.d/90-alice
Then run visudo -c. If visudo -c ever reports a fault in /etc/sudoers itself, do not overwrite it from here. Compare it with the saved copy first, using a command that only reads:
diff /etc/sudoers.2026-11-22 /etc/sudoers
The steps here change only files under /etc/sudoers.d, never /etc/sudoers, so a difference there was made by someone else; ask that person before anything is copied back.
A drop-in file that sudo skips
If step 5 showed a drop-in whose name contains a . (for example 90-ops.conf), sudo is not reading it, so nobody has tested its content.
Check two things first. Both only read. The new name must not exist, so stop if the first command shows a file. The second command checks the file's syntax on its own; the visudo manual says the policy is evaluated in its entirety, so a clean result is not sufficient, and a reported error means you stop and fix the file first:
ls -l /etc/sudoers.d/90-ops
visudo -c -f /etc/sudoers.d/90-ops.conf
First save the current listing:
ls -l /etc/sudoers.d > /root/sudoers.d-list-rename.2026-11-22
Risk: the next command renames a policy file, and the rules in it start applying at once. The visudo manual says "if visudo believes there to be a syntax error, so will sudo", so a faulty file can stop sudo working for everyone.
Rename the file so that its name has no ., without overwriting anything (the mv manual describes -n as "do not overwrite an existing file"), then check the policy:
mv -n /etc/sudoers.d/90-ops.conf /etc/sudoers.d/90-ops
visudo -c
To undo it: first confirm that the renamed file exists and the old name is free, then rename it back and check the policy:
ls -l /etc/sudoers.d/90-ops /etc/sudoers.d/90-ops.conf
mv -n /etc/sudoers.d/90-ops /etc/sudoers.d/90-ops.conf
visudo -c
Then compare ls -l /etc/sudoers.d with /root/sudoers.d-list-rename.2026-11-22.
Example (illustrative): On web01, a Debian-family server, the engineer ops1 creates the account alice. Her first sudo apt-get update prints alice is not in the sudoers file. As ops1, the engineer runs id alice, which lists only her own group, and getent group sudo, which lists ops1 and no one else. The engineer saves both outputs and runs usermod -aG sudo alice. id alice now includes sudo. visudo -c reports no errors. alice opens a new session and sudo apt-get update runs after her password prompt.
Confirm the fix
id alicelists the group (orsudo -l -U aliceas root shows the rule you added).visudo -cexits with status 0, which the manual says means the check completed successfully.- In a new session,
alicecan runsudo -land then onesudocommand that she is meant to run, without the message.
What to watch afterwards
- Keep the list of members of the administrative group short and checked on a schedule.
- Prefer groups to per-user rules, and keep per-user rules in separate files under
/etc/sudoers.dso a mistake affects one file. - Treat each message "is not in the sudoers file" as an access request or a probe: the sudoers manual says mail is sent to
mailtoby default.
Read next
Related articles you may want next.
- Troubleshooting"sudo: unable to resolve host": fix the hostname and /etc/hosts after a renamesudo says unable to resolve host after a rename or clone? Test the name with getent, fix /etc/hosts or DNS, and stop cloud-init undoing it.Read article
- TroubleshootingLinux account locked after failed logins: read and reset pam_faillockLinux refuses the right password after failed logins? Read the pam_faillock record, find the source of the failures, then reset one user safely.Read article
- Backup & RecoveryGetting into a Linux server you cannot log in to: rescue targets, rd.break and boot loader passwordsPlanning console access to a locked-out Linux server: rescue and emergency targets, rd.break, debug shells, and boot loader passwords.Read article
Risks and limits
- These commands have not been run or lab-tested.
- Full sudo rights equal root on the server. Grant the narrowest rule that does the job.
- The visudo manual says that choosing
Qat the "What now?" prompt saves a file even though visudo found a syntax error, and calls it a choice to use "with extreme caution because if visudo believes there to be a syntax error, so will sudo". Useeto edit again orxto leave without saving. - Group names differ between systems: the Ubuntu documentation names
sudo, and the sudoers manual's own example nameswheel. Read the sudoers file on the server to see which group it grants. - LDAP, SSSD or Active Directory groups are not covered.
Sources
- sudoers manual — sudo.ws, current manual page, no date shown, accessed 22 November 2026
- visudo manual — sudo.ws, current manual page, no date shown, accessed 22 November 2026
- sudo manual — sudo.ws, current manual page, no date shown, accessed 22 November 2026
- sudo ChangeLog — sudo.ws, entries dated February 2022, accessed 22 November 2026
- logging.c at tag 1.8.31 — sudo source, no date shown, accessed 22 November 2026
- logging.c at tag 1.9.5p2 — sudo source, no date shown, accessed 22 November 2026
- logging.c at tag 1.9.16p2 — sudo source code at a fixed tag, no date shown, accessed 22 November 2026
- User management — Ubuntu Server documentation, last updated 26 June 2026, accessed 22 November 2026
- mv(1) — GNU coreutils 9.11 manual page, April 2026, accessed 22 November 2026
- usermod(8) — shadow-utils 4.19.0, 08/04/2026, accessed 22 November 2026
- id(1) — GNU coreutils 9.11, April 2026, accessed 22 November 2026
- getent(1) — Linux man-pages 6.19, 2026-02-08, accessed 22 November 2026
This article was originally published on .