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?
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 foundmeans sudo is not installed at all (common on minimal Debian and in containers). Usesu -andapt install sudo.sudo: /etc/sudoers is owned by uid 1000, should be 0orsudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit setis a permission mess on the sudo files themselves, usually from a recklesschown -Rorchmod -R; fix from a root shell withchown root:root /etc/sudoers && chmod 0440 /etc/sudoersandchmod 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 0if 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
- fail2ban: ban hosts that fail to log in too often fail2ban/fail2ban The standard intrusion-prevention daemon on Linux servers: it watches logs or the journal for repeated failures and adds temporary firewall rules against the offending addresses. GitHub
- dev-sec ansible-collection-hardening: tested hardening roles for Linux, SSH and nginx dev-sec/ansible-collection-hardening An Ansible collection that applies a well-documented hardening baseline to Linux hosts, the SSH server and client, nginx and MySQL, with every setting adjustable through variables. GitHub
- Atomic Red Team: small tests that check whether your detections fire redcanaryco/atomic-red-team Atomic Red Team is a library of tiny, documented tests, each reproducing one attacker technique from MITRE ATT&CK, that defenders run in their own lab to confirm their monitoring notices it. GitHub
- Lynis: a security audit of a Linux or Unix host with hardening suggestions CISOfy/lynis Lynis is a shell script that inspects a Linux, BSD or macOS system you administer, tests hundreds of settings and services, and prints warnings and concrete hardening suggestions with a score. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +3,948 chars