Troubleshooting

'User is not in the sudoers file': why sudo refuses you and how to fix it

Fix user is not in the sudoers file on Debian, Ubuntu and RHEL: get root with su -, add the user to sudo or wheel, log in again or repair sudoers with visudo.

Published ~7 min read
On this page

Short answer: sudo found no rule in /etc/sudoers that matches your account, so it refuses. Become root another way (su - with the root password), add the user to the admin group (sudo on Debian and Ubuntu, wheel on Fedora, RHEL, AlmaLinux and Rocky Linux), then log out and log back in before you try again.

Debian · Ubuntu (wheel on RHEL family)
su -                          # root password, not yours; note the dash
usermod -aG sudo alice        # usermod -aG wheel alice on Fedora, RHEL, Alma, Rocky
exit

# alice: log out completely, log back in, then
id                            # the list must now contain sudo (or wheel)
sudo whoami                   # prints: root

Nothing is “reported” to anyone you need to worry about: sudo writes the refusal to the system log and, only if the server can send mail, mails root. The rest of this page explains which wording your sudo prints and what to do when su - is not an option.

Which message does your sudo print?

The wording depends on the sudo version. We read it in sudo’s own source (plugins/sudoers/logging.c for 1.9.9, 1.9.10 and the current branch) and in the changelog: sudo 1.9.10 dropped “This incident will be reported” and prints “This incident has been reported to the administrator.” on a second line, but only when a mail program is configured and present. Ubuntu switched its default sudo to the Rust rewrite sudo-rs in 25.10, which words the refusal differently again.

sudo versionWhat it printsShipped in
1.9.9 and olderalice is not in the sudoers file. This incident will be reported.Ubuntu 22.04 (1.9.9), Debian 11 (1.9.5p2)
1.9.10 and neweralice is not in the sudoers file. plus This incident has been reported to the administrator. only if mail worksDebian 12 (1.9.13p3), Debian 13 (1.9.16p2), Ubuntu 24.04 (1.9.15p5), Rocky 9.8 (1.9.17p2)
sudo-rsI'm sorry alice. I'm afraid I can't do thatUbuntu 25.10 and 26.04 (default provider)

Two related messages come from the same code and mean something slightly different:

  • alice is not allowed to run sudo on web1. sudo found rules for you, but none for this host name. Look for a rule with a host list instead of ALL.
  • Sorry, user alice is not allowed to execute '/usr/bin/apt update' as root on web1. You do have rules, just not for that command. Run sudo -l to see what you may run.

Check what is missing first

Three read-only commands tell you which case you are in: your current groups, the members of the admin group, and the rule that grants the group its rights. This is the real output on one of our Debian 12 servers, run as root:

output · Debian 12 (as root)
$ id
uid=0(root) gid=0(root) groups=0(root)
$ getent group sudo
sudo:x:27:
$ ls -l /etc/sudoers.d
total 8
-r--r----- 1 root root  273 Jun 11 22:08 90-cloud-init-users
-r--r----- 1 root root 1096 Jun 27  2023 README
$ grep -E '^%(sudo|wheel)' /etc/sudoers
%sudo	ALL=(ALL:ALL) ALL

The empty field after sudo:x:27: means no user is in the group, and the active %sudo line means membership alone would be enough. The 90-cloud-init-users file is how cloud images grant their default user sudo: the rule lives in a drop-in, not in the group. Read your own results like this:

  • Your user is not in getent group sudo (or wheel): add it, see the next section.
  • It is in the group, but id does not show the group: your session is older than the change. Log in again.
  • id shows the group, and the grep finds nothing: the group rule is missing or commented out. Fix sudoers.

As a normal user you cannot read /etc/sudoers (mode 0440, owner root), so the last check needs root too.

Fix it with the root password

If root has a password, su - gives you a root shell. Use the dash: plain su keeps your own PATH, and on Debian that PATH lacks /usr/sbin, which is where usermod lives (the su command guide covers the difference). Then add the user with -aG; without -a, usermod -G replaces all supplementary groups instead of adding one, as adding a user to a group explains.

as root
usermod -aG sudo alice        # Debian, Ubuntu
usermod -aG wheel alice       # Fedora, RHEL, AlmaLinux, Rocky Linux
getent group sudo             # check: sudo:x:27:alice

Red Hat’s documentation shows the default rule as %wheel ALL=(ALL) ALL, so the wheel group is the one that counts there. Adding a Debian user to wheel, or a Rocky user to sudo, changes nothing unless a sudoers rule names that group.

Why Debian did not give your user sudo

This is the usual cause of “is not in the sudoers file” on Debian. The Debian installer manual says that if you leave the root password empty, root is disabled, sudo is installed and the first user may use sudo. If you do set a root password, that last step does not happen: your first user is an ordinary account. The fix is the one above, run after su - with the root password you chose during installation.

Added to the group, still refused? Log in again

Group membership is read when a session starts. A shell that was open before usermod ran keeps its old group list, and sudo passes that list to its policy, per the group_source entry in sudo.conf(5). So id alice may already show sudo while plain id in your old session does not.

check stored vs current groups
id alice      # what /etc/group says now
id            # what this session has; needs sudo or wheel before sudo works

Close the session completely and open a new one: log out of the desktop, or open a new SSH connection (a new tab on a multiplexed SSH connection does not count). newgrp sudo starts a single new shell with the group active, but only that shell and what you start from it get the group, so it is a test, not a fix.

No root password and no other sudo user

Then nobody on the running system can change the rules, and you have to get root from outside it. Your options, from least to most invasive:

  • Another account with sudo, or root login with an SSH key if that is still set up. Use it and run the fix above.
  • A live or rescue system booted from an ISO image or USB stick through a local or remote console. Mount the installed root file system and run the fix in a chroot.
  • Recovery mode or init=/bin/bash from the GRUB menu, which you reach through a local or out-of-band console. Recovery mode usually asks for the root password; if root is locked, it stops with Cannot open access to console, the root account is locked.
from a rescue or live system (device names vary, lsblk shows them)
lsblk
mount /dev/vda1 /mnt
chroot /mnt /usr/sbin/usermod -aG sudo alice
umount /mnt
init=/bin/bash (append to the linux line in GRUB, boot)
mount -o remount,rw /
/usr/sbin/usermod -aG sudo alice     # or: passwd root
sync
exec /sbin/init                      # continue a normal boot

The group is right, but sudoers is broken

If id shows the group and you still get the message, the rule itself is the problem. Three cases cover most of them:

  • The group line is commented out. Fedora’s docs mention this for the %wheel line. Remove the # with visudo.
  • A drop-in has a syntax error. Since sudo 1.9.3, sudo recovers from a syntax error by discarding the rest of the broken line (sudoers(5), error_recovery). If that line was your rule, sudo carries on as if you had none.
  • The drop-in is never read. Per Debian’s /etc/sudoers.d/README, sudo skips files whose name ends in ~ or contains a dot, so alice.conf does nothing. sudoers(5) also lists a world-writable /etc/sudoers as an error.
as root: check and edit safely
visudo -c                        # checks /etc/sudoers and every included file
visudo                           # edit the main file
visudo -f /etc/sudoers.d/alice   # edit or create one drop-in

visudo checks the syntax before it saves. On an error it asks What now?: type e to edit again or x to discard. Q saves the broken file anyway, which visudo’s manual warns against. When no sudoers file can be parsed at all, sudo stops with no valid sudoers sources found, quitting, and you are back to getting root from outside. The full rule syntax is in sudoers(5).

sudo is not installed at all

If the shell answers sudo: command not found instead, there is no sudo package to refuse you. Install it as root (apt install sudo after su - on Debian), then add your user as above. When usermod itself is missing in that root shell, you used su without the dash; usermod: command not found walks through it.

On a VPS or dedicated server

A fresh server image often logs you in as root over SSH, so there is no sudo user yet. Create one, add it to sudo or wheel, and test sudo whoami in a new SSH session while the root session stays open. Only then turn off root login over SSH; if you do it the other way round, the console is your only way back in. The complete walkthrough is in creating a sudo user, and the remaining first-login steps are in initial server setup.

Frequently asked

What does 'is not in the sudoers file' mean?

sudo checked /etc/sudoers and the files it includes and found no rule that matches your account, neither for your user name nor for a group you are in. On Debian and Ubuntu the usual rule covers the sudo group, on Fedora and the RHEL family the wheel group. Become root with su -, add yourself to that group, and log in again.

Is 'this incident will be reported' anything to worry about?

No one is alerted in real time. sudo logs the refusal to the system log and, if a mail program is installed, mails root. Since sudo 1.9.10 the sentence only appears when mail can actually be sent, and then it reads 'This incident has been reported to the administrator.' on its own line.

I added myself to the sudo group and still get the error. Why?

Your session still has the group list it had at login, and sudo uses that list. Log out completely and log back in, or open a new SSH connection, then check that plain id shows sudo (or wheel). If it does and sudo still refuses, the group rule in /etc/sudoers is missing or commented out; check it as root with visudo -c and visudo.

How do I fix it without the root password?

Use another account that has sudo, or root login with an SSH key if one is set up. Otherwise you need root from outside the running system: boot a live or rescue system from an ISO image, mount the root file system and run usermod in a chroot, or boot with init=/bin/bash from GRUB.

Related articles

All troubleshooting