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's 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.
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.
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