Skip to main content
“sudo: command not found” means sudo isn’t installed: log in as root and install it with apt install sudo or dnf install sudo. “alex is not in the sudoers file” means the user has no sudo rights: as root, run usermod -aG sudo alex on Ubuntu/Debian or usermod -aG wheel alex on AlmaLinux/Rocky, then log out and back in. Both fixes need root, through su - or the VNC console.
Older sudo versions end the second message with This incident will be reported. instead.

Before you start

  • All fixes need root. If you know the root password, switch with su -. If not, reset the root password and log in as root on the VNC console. On a dedicated server, open a ticket for KVM/IPMI access.
  • Commands below run as root, so they have no sudo in front.

Cause 1: sudo isn’t installed (command not found)

Minimal installs, for example Debian installed with a root password, don’t include sudo. Check:
Fix as root:
If /usr/bin/sudo exists but the shell can’t find it, your PATH is broken. Check with echo $PATH: it should contain /usr/bin. Fix the line that changes PATH in ~/.bashrc or ~/.profile.

Cause 2: The user isn’t allowed to use sudo

Check the user’s groups:
Ubuntu and Debian give sudo rights to the sudo group; AlmaLinux and Rocky use wheel. Fix as root:
Keep the -a: without it, usermod -G removes the user from all other groups. Then log out and back in. Group changes only apply to new logins. For a full walkthrough, see create a sudo user.

Cause 3: sudo asks for a password you don’t know

sudo asks for your own password, not root’s. Users created only with an SSH key may have no password at all, so every attempt ends with Sorry, try again. or sudo: a password is required. Fix as root, set a password for the user:
Or allow that user sudo without a password (convenient, but anyone with the user’s SSH key then has full root access):

Cause 4: A broken sudoers file

A typo in /etc/sudoers or a file in /etc/sudoers.d/ makes sudo print errors, ignore the broken rule, or refuse to run at all, depending on the error and sudo version:
Fix as root: check every file and correct the one reported:
visudo -c should end with parsed OK for every file. Always edit sudoers with visudo: it refuses to save a file with errors.
Never edit /etc/sudoers with a plain editor, and don’t change its permissions (440, owned by root). A broken or world-writable sudoers file disables sudo for everyone, and then you need the console or rescue mode to repair it.
If a chmod -R or chown -R on / or /usr changed system files, sudo stops with sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set. As root:
A recursive permission change usually damages much more than sudo. Restore from a backup if other programs fail too.

Cause 5: “Permission denied” even with sudo

In sudo echo "text" > /etc/example.conf, only echo runs as root. The > redirection is done by your own shell, as your user. Fix: let a root process write the file:
tee -a appends instead of overwriting. See Linux file permissions explained.

How to check it worked

Log in again as the user and run:

Frequently asked questions

Is the “incident” really reported to someone?

sudo logs the attempt (in the journal or /var/log/auth.log on Ubuntu/Debian, /var/log/secure on AlmaLinux/Rocky) and, if mail is set up, can email root. Nobody outside your server is notified.

I added the user to the group but it still fails. Why?

The current session still has the old groups. Log out completely and log in again, then check with id.

Should I just use root instead of sudo?

Using a sudo user is safer: it limits mistakes and lets you disable root login over SSH.

VPS and dedicated server guides

Every guide in this section.

Create a sudo user

Set up an admin user properly.

Manage users and groups

useradd, usermod and groups.

File permissions explained

chmod and chown without surprises.

Disable root login

The next step once sudo works.

Checked against the official sudo manual, sudoers manual and visudo manual on 4 November 2026; the “not in the sudoers file” message, adding the user to the sudo group, the sudoers syntax error, visudo -c / -cf, the redirection error and the tee fix were tested with a temporary user on Ubuntu 24.04 LTS (sudo 1.9.15p5). The AlmaLinux wheel steps were not tested.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026