What the Message Means
Before it runs anything as root, sudo checks /etc/sudoers and the files under /etc/sudoers.d. If no rule matches your account, it stops and reports that you are not in the sudoers file. Classic sudo adds that the incident is reported; sudo-rs, the default sudo on Ubuntu 26.04, words the message differently. The report is a line in the system log: the journal, /var/log/auth.log on Debian and Ubuntu where rsyslog writes it, or /var/log/secure on AlmaLinux and Rocky Linux. Classic sudo can also mail a notice to root when a mail program is installed. How sudo works is explained in what is sudo.
Why It Happens
The account exists and can log in, but it has no admin rights. The usual causes:
- A new account: the user was created but never added to the admin group.
- The Debian installer: when you set a root password during installation, the first user is not added to the sudo group.
- A group change gone wrong:
usermod -Gwithout-areplaced all of the user's groups.
Check the Account
id
groups deploy
id lists your groups. Look for sudo on Debian and Ubuntu or wheel on AlmaLinux and Rocky Linux. Once sudo works, sudo -l lists what you may run.
Fix 1: Add the User to the Admin Group
Work as root or as another administrator. su - asks for the root password, not yours. On Debian and Ubuntu:
su -
usermod -aG sudo deploy
exit
On AlmaLinux and Rocky Linux:
su -
usermod -aG wheel deploy
exit
The -a matters: without it, -G replaces every supplementary group of the user. See usermod for the other options. Group membership is read at login, so log out completely, reconnect, and test:
id
sudo whoami
The second command prints root when sudo works. The full setup of a new admin account is in how to create a sudo user on Ubuntu.
Fix 2: A Rule File Written with visudo
Warning: a syntax error in the sudo configuration breaks sudo for every account. Never edit these files with a plain editor; visudo checks the syntax before it saves. Keep a root session open until the change is tested in a second session.
visudo -f /etc/sudoers.d/deploy
Add one line and save:
deploy ALL=(ALL:ALL) ALL
Then check the whole configuration with visudo -c. Use a file name without a dot: both classic sudo and sudo-rs skip files in that folder whose names contain a dot or end in ~. The format is covered in the sudoers file.
When No Administrator Account Works
- You know the root password: log in as root on your provider's console, or with
su -, and apply Fix 1. The console works even when root login over SSH is turned off. - Ubuntu without a root password: the root account is usually locked on Ubuntu, so
su -fails. Use the rescue system. - Rescue system: boot it from your provider's control panel, find the root disk with
lsblk, mount it, add the user to the group inside it, and reboot from the normal disk.
mount /dev/vda1 /mnt
chroot /mnt usermod -aG sudo deploy
umount /mnt
Use wheel instead of sudo on AlmaLinux and Rocky Linux, and run touch /mnt/.autorelabel before the unmount: files changed from a rescue system can lose their SELinux labels, and the relabel at the next boot restores them.
What Not to Do
- Changing permissions on the files: they belong to root and are created with mode 0440. Another owner or a writable mode can make sudo refuse to run.
- Passwordless rules for everyone: a NOPASSWD rule for all users turns any stolen account into root.
- Working as root all day: fix sudo once instead, so that every command has a user name in the log.