Fix "user is not in the sudoers file" on Linux
is not in the sudoers fileThis incident will be reportedsudo: command not foundThis means your user doesn't have permission to use sudo. The fix is to add it to the right group — but you need an account that already has root/sudo to do it. Here is both.
Add the user to the sudo group
As root (or another sudo user), add your user to the admin group — sudo on Debian/Ubuntu, wheel on RHEL/Alma/Rocky:
# Debian/Ubuntu
usermod -aG sudo username
# RHEL/Alma/Rocky
usermod -aG wheel username
# then log out and back in
No root or sudo access at all?
If no account can elevate, use your provider's VNC/serial console or boot to single-user/rescue mode to log in as root, then run the command above.
Never edit /etc/sudoers directly — a syntax error locks everyone out of sudo. Always use visudo, which validates the file before saving.
"sudo: command not found"
That's different — sudo isn't installed. As root: apt install sudo or dnf install sudo.
Add the user to sudo (Debian) or wheel (RHEL) as root, re-login, and always edit sudoers with visudo.
Cause: sudo installed but the group name differs
A minimal or custom Linux image sometimes uses a non-default admin group name, or ships without sudo group membership pre-wired even though sudo itself is installed. Check which group actually grants access on your distro (look inside /etc/group for sudo or wheel) before adding the user.
Granting access to only specific commands (least privilege)
Full sudo access isn't always appropriate. For a service account that only needs to restart one service, add a narrow rule via visudo instead of full group membership — for example allowing only a specific systemctl restart command without a password, rather than blanket root.
How to prevent sudo lockouts
- Always keep at least one account (or your host's console access) with confirmed working sudo/root before removing another.
- Test a new sudoers rule in a second terminal session before closing the one that still has access.
- Never edit /etc/sudoers directly — always visudo.
- Document who has sudo and why, especially on shared team servers.
Related errors
Locked out over SSH specifically, not sudo? See SSH permission denied (publickey). For a full lockdown checklist including SSH keys and sudo, see how to harden SSH and how to secure a Linux VPS.
A VDS with full root + console
Our VDS plans give you full root and VNC console access, so you're never locked out — protected NVMe in Frankfurt.
Frequently asked questions
How do I fix "user is not in the sudoers file"?
As root or another sudo user, add your account to the sudo group (Debian/Ubuntu) or wheel group (RHEL/Alma/Rocky) with usermod -aG, then log out and back in.
What if no user has sudo or root access?
Use your provider's VNC/serial console or boot into rescue/single-user mode to log in as root, then add your user to the sudo/wheel group.
How do I safely edit the sudoers file?
Always use the visudo command, never a normal editor. visudo checks the syntax before saving, so a typo can't lock everyone out of sudo.
Can I give a user sudo access without a password prompt?
Yes, with a visudo rule such as NOPASSWD against a specific command list. Use this sparingly — it removes a layer of protection if that account's SSH key or session is ever compromised.
I removed myself from the sudo group by accident - now what?
If you still have another sudo/root session open, don't close it — use it to add yourself back immediately. If not, use your host's VNC/console or rescue mode to log in as root and fix it.
What's the difference between the sudo group and the wheel group?
They serve the same purpose — granting sudo access — but different distro families default to different names: Debian/Ubuntu use "sudo", RHEL/AlmaLinux/Rocky use "wheel". Check the sudoers configuration (via visudo) to see which one is actually set up.
Related articles
Fix SSH "Connection refused" / "Connection timed out"
SSH "connection refused" vs "timed out" — what each means and the exact steps to fix them.
Read fix Linux & VPSFix "Permission denied" on Linux (chmod & chown Explained)
"Permission denied" on a script or file? Understand chmod/chown and fix it the right way.
Read fix Linux & VPSHow to Check CPU, RAM & Disk Usage on a Linux Server
The essential commands to check CPU, RAM and disk on Linux — and find what's eating them.
Read fix