Skip to content
Commitpedia
Log in Join & edit

Fix: user is not in the sudoers file

sudo refuses because your account is not allowed to use it. Add the user to the sudo group (Debian, Ubuntu) or wheel group (RHEL, Fedora, Arch) from a root shell, then log out and back in.

Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?

Edit history of Fix: user is not in the sudoers file: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min
alice is not in the sudoers file.  This incident will be reported.
alice is not in the sudoers file.
Sorry, user alice is not allowed to execute '/usr/bin/apt update' as root on server1.

sudo only works for users listed in /etc/sudoers or in a file under /etc/sudoers.d/, directly or through a group. Your user is not covered by any rule, so sudo denies the command and logs the attempt. The ominous “will be reported” means a line in the auth log and possibly a mail to root, nothing more.

Cause 1: the user was never added to the admin group

A user created with adduser or useradd is a plain user. Distributions grant sudo through a group: sudo on Debian and Ubuntu, wheel on RHEL, Fedora, Alma, Rocky, Arch and openSUSE, admin on macOS. You need root, or another user who already has sudo, to add the group.

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
# From a root shell or a user that already has sudo
sudo usermod -aG sudo alice      # Debian, Ubuntu
sudo usermod -aG wheel alice     # RHEL, Fedora, Arch, openSUSE

# Check the rule actually exists for that group
sudo grep -E '^%(sudo|wheel)' /etc/sudoers /etc/sudoers.d/* 2>/dev/null

Careful: usermod -G without -a replaces all the user’s supplementary groups instead of adding one. Always write -aG.

The user must log out and back in (or start a fresh SSH session) before the new group applies; id alice or groups shows whether it is there. A running desktop session keeps the old group list.

Cause 2: the group exists but is commented out in sudoers

On some minimal installs, the %wheel line in /etc/sudoers is commented out. Edit sudoers only with visudo, which checks the syntax before saving; a syntax error in that file locks everyone out of sudo.

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo visudo
# uncomment one of:
# %wheel ALL=(ALL:ALL) ALL
# %sudo  ALL=(ALL:ALL) ALL

# Or add a drop-in for a single user
echo 'alice ALL=(ALL:ALL) ALL' | sudo tee /etc/sudoers.d/alice
sudo chmod 0440 /etc/sudoers.d/alice
sudo visudo -c                   # syntax check all files

Cause 3: there is no one with sudo left

If this is the only account and root has no password (Ubuntu’s default), you need a root shell another way. Options, from least to most invasive: su - if root has a password; log in on the console as root; a cloud provider’s serial console or rescue mode; or reboot into single-user or recovery mode (GRUB, choose the recovery entry, then root shell) and run the usermod command there. On a VM, mounting the disk from another VM and editing /etc/group works too.

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
# In recovery mode the root file system may be read-only
mount -o remount,rw /
usermod -aG sudo alice
reboot

Cause 4: a restricted rule, not a missing one

is not allowed to execute '/usr/bin/apt' as root means your user has sudo for some commands but not this one. sudo -l lists what you may run. Ask the administrator to extend the rule rather than working around it.

Check that it is fixed

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
id                   # the group is listed (after a new login)
sudo -l              # shows (ALL : ALL) ALL or the allowed commands
sudo -v              # asks for your password and succeeds silently

When it is not what you think

  • sudo: command not found means sudo is not installed at all (common on minimal Debian and in containers). Use su - and apt install sudo.
  • sudo: /etc/sudoers is owned by uid 1000, should be 0 or sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set is a permission mess on the sudo files themselves, usually from a reckless chown -R or chmod -R; fix from a root shell with chown root:root /etc/sudoers && chmod 0440 /etc/sudoers and chmod 4755 /usr/bin/sudo.
  • Sorry, try again. is a wrong password, and on Ubuntu it asks for your password, not root’s.
  • In Docker containers there is usually no sudo and you are already root; use docker exec -u 0 if you are not.

Official documentation

Did this work for you?

No votes yet. Be the first.

If it did not work, the report form below tells the editors what went wrong.

See also

  • 0177 Users, groups and sudo on Debian, Ubuntu and RHEL How Linux accounts and groups work, how to create users, and how sudo gives admin rights through the sudo group on Debian/Ubuntu… Beginner · Explains an idea · Linux Article Users, sudo & hardening 15 Oct 2026
  • 0178 Create a sudo user with an SSH key and disable password login A bash script that creates an admin user in the sudo or wheel group, installs their SSH public key and can switch… Advanced · Step by step · Linux Script Keys & config · Users, sudo & hardening 15 Oct 2026
  • 0249 Set up and harden a fresh Linux server in one afternoon Take a new Ubuntu, Debian or Rocky/Alma server from first login to a safer baseline: sudo admin, SSH keys only, firewall, automatic… Beginner · Guided project · Linux Article Networking & firewalls · Packages & updates · Users, sudo & hardening 15 Oct 2026
  • 0317 Fix: Permission denied when running a script (chmod +x) bash: ./script.sh: Permission denied means the file exists but you may not execute it. Usually the execute bit is missing; sometimes the… Beginner · Fixes an error · Linux, macOS Article Basics · Users, sudo & hardening 15 Oct 2026
  • 0352 Harden a fresh Linux server in 30 minutes The baseline for any new Debian, Ubuntu or RHEL-family server: updates on, a non-root user with sudo, SSH keys only, a firewall… Beginner · Step by step · Linux Article Server hardening · Users, sudo & hardening 15 Oct 2026
  • 0353 fail2ban: block repeated failed logins Install fail2ban, enable the sshd jail with sane ban times, whitelist your own address, read the ban list, unban someone, and add… Intermediate · Step by step · Linux Article Server hardening · SSH 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Dominik +3,948 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?