> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Fix "sudo: command not found" and "Not in the sudoers file"

> Fix "sudo: command not found" by installing sudo as root, and "not in the sudoers file" by adding the user to the sudo or wheel group, then log in again.

"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.

```text theme={null}
-bash: sudo: command not found
alex is not in the sudoers file.
This incident has been reported to the administrator.
```

Older sudo versions end the second message with `This incident will be reported.` instead.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux and Rocky Linux 9 / 10 | The root password, or console access |

## Before you start

* All fixes need **root**. If you know the root password, switch with `su -`. If not, [reset the root password](https://help.freakhosting.com/portals/vps-panel/how-to-reset-your-vps-root-password.md) and log in as root on the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md). On a dedicated server, [open a ticket](https://freakhosting.com/clientarea/submitticket.php) 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:**

```bash theme={null}
ls -l /usr/bin/sudo
```

**Fix** as root:

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> su -
> apt update && apt install sudo
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> su -
> dnf install sudo
> ```

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:

```bash theme={null}
id alex
```

Ubuntu and Debian give sudo rights to the `sudo` group; AlmaLinux and Rocky use `wheel`.

**Fix** as root:

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> usermod -aG sudo alex
> ```

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> usermod -aG wheel alex
> ```

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](https://help.freakhosting.com/portals/other/how-to-create-a-sudo-user-on-linux.md).

## 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:

```bash theme={null}
passwd alex
```

Or allow that user sudo without a password (convenient, but anyone with the user's SSH key then has full root access):

```bash theme={null}
visudo -f /etc/sudoers.d/90-alex
```

```text theme={null}
alex ALL=(ALL) NOPASSWD: ALL
```

## 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:

```text theme={null}
/etc/sudoers.d/90-alex:1:18: syntax error
alex ALL=(ALL NOPASSWD: ALL
                 ^~~~~~~~~
```

**Fix** as root: check every file and correct the one reported:

```bash theme={null}
visudo -c
visudo -f /etc/sudoers.d/90-alex
```

`visudo -c` should end with `parsed OK` for every file. Always edit sudoers with `visudo`: it refuses to save a file with errors.

> [!WARNING]
>
> 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](https://help.freakhosting.com/portals/vps-panel/how-to-use-rescue-mode.md) 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:

```bash theme={null}
chown root:root /usr/bin/sudo
chmod 4755 /usr/bin/sudo
```

A recursive permission change usually damages much more than sudo. Restore from a [backup](https://help.freakhosting.com/portals/vps-panel/how-to-schedule-and-restore-backups.md) if other programs fail too.

## Cause 5: "Permission denied" even with sudo

```text theme={null}
-bash: /etc/example.conf: Permission denied
```

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:

```bash theme={null}
echo "text" | sudo tee /etc/example.conf
echo "more" | sudo tee -a /etc/example.conf
```

`tee -a` appends instead of overwriting. See [Linux file permissions explained](https://help.freakhosting.com/portals/other/linux-file-permissions-explained-chmod-and-chown.md).

## How to check it worked

Log in again as the user and run:

```bash theme={null}
sudo whoami
```

```text theme={null}
root
```

## 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](https://help.freakhosting.com/portals/other/how-to-disable-root-login-over-ssh.md).

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every guide in this section.

> [card] [Create a sudo user](https://help.freakhosting.com/portals/other/how-to-create-a-sudo-user-on-linux.md)
>
> Set up an admin user properly.

> [card] [Manage users and groups](https://help.freakhosting.com/portals/other/how-to-manage-users-and-groups-on-linux.md)
>
> useradd, usermod and groups.

> [card] [File permissions explained](https://help.freakhosting.com/portals/other/linux-file-permissions-explained-chmod-and-chown.md)
>
> chmod and chown without surprises.

> [card] [Disable root login](https://help.freakhosting.com/portals/other/how-to-disable-root-login-over-ssh.md)
>
> The next step once sudo works.

***

> [!NOTE]
>
> **Checked against the official [sudo manual](https://www.sudo.ws/docs/man/sudo.man/), [sudoers manual](https://www.sudo.ws/docs/man/sudoers.man/) and [visudo manual](https://www.sudo.ws/docs/man/visudo.man/)** 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.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.