# How to Add a User to Sudoers in Linux

Canonical URL: https://pendrivelinux.com/how-to-add-user-to-sudoers-list/
Published: 2007-10-05
Last modified: 2026-11-28
Description: Learn how to add a user to sudoers or the sudo/wheel group on Ubuntu, Debian, Fedora, Arch, and other Linux distributions using visudo.

---

To give a user administrative access in Linux, add them to the `sudo` group on Ubuntu and Debian, or the `wheel` group on Fedora, Arch, CentOS, openSUSE, and Gentoo. You can also grant access with an individual rule in `/etc/sudoers` or a file in `/etc/sudoers.d/`. Always edit these rules with `visudo`, which checks syntax before saving and helps prevent mistakes that could break sudo access.

This guide covers three ways to grant sudo access-group membership, direct sudoers file edits, and the modern `/etc/sudoers.d/` drop-in method-across Ubuntu, Debian, Fedora, Arch, CentOS, openSUSE, and Gentoo. It also covers the "user is not in the sudoers file" error, which is one of the most common reasons people land on this page in the first place.

## Add User to Sudoers: Grant Administrative (Root) Access

![Add User to Sudoers](https://pendrivelinux.com/wp-content/uploads/add-user-to-sudoers-600x350.webp)

Using the terminal to add a user to the sudoers file on Debian based systems like Ubuntu.

**Quick Summary: Add a User to Sudoers**

- Ubuntu and Debian: `usermod -aG sudo username`
- Fedora, CentOS, Arch, openSUSE, Gentoo: `usermod -aG wheel username`
- Edit sudoers safely using `sudo visudo`
- Manual entry: `username ALL=(ALL) ALL`
- Preferred modern method: a drop-in file in `/etc/sudoers.d/`
- Verify access with `sudo -l` or `sudo whoami`
- Log out and back in-or run `newgrp sudo`-for group changes to take effect

On Debian and Ubuntu based systems, users in the `sudo` group are allowed to execute commands as root. Most other Linux distributions-Fedora, CentOS, Arch, openSUSE, Gentoo-use the `wheel` group for the same purpose instead. Both work the same way under the hood: sudo checks `/etc/sudoers` (and anything included from `/etc/sudoers.d/`) to see whether the group, or the user directly, has permission.

**Important:**
 You must already have administrative access to add another user to the sudo group or edit sudoers. If your current account cannot run `sudo`, use an existing root account or an authorized recovery method; setting a root password is not required on every Linux system and should not be treated as a universal first step. See the guide to the [default root password in Linux](https://pendrivelinux.com/what-is-the-default-root-password/) for distribution-specific context.

### If You Do Not Have Sudo Access

The commands below must be run from an account that already has administrative privileges. If your account is not authorized to use `sudo`, do not try to grant itself access with a command that requires sudo. Sign in with an existing administrator account or use the distribution's documented recovery procedure to regain authorized administrative access.

## Add a User to Sudoers on Ubuntu and Debian

1. Open a terminal: **Ctrl + Alt + T**
2. From an account that already has sudo access, add the target user to the sudo group (replace `username`):

```
sudo usermod -aG sudo username
```

If you are already logged in as root, omit `sudo` from the command. Do not use `sudo su` as a workaround if your account does not already have sudo privileges.

**Note:** The target user must fully log out and log back in for the new group membership to take effect. A new login session is the clearest way to verify the change.

**Note on Debian specifically:** a minimal Debian install may not add the first user to the `sudo` group automatically, and `sudo` itself may not even be installed. If `usermod -aG sudo username` fails or sudo isn't recognized, install it first with `apt -y install sudo`.

### Fix "bash: sudo: command not found"

If you encounter the error **bash: sudo: command not found**, install sudo as root.

```
apt -y install sudo
```

Then test sudo access.

```
su - username
sudo whoami
```

### Fix "username is not in the sudoers file. This incident will be reported."

This is the error sudo shows when the account exists but has no sudo privileges at all-no group membership and no entry in `/etc/sudoers`. To fix it:

1. Log in as (or switch to) an account that already has root or sudo access.
2. Add the affected user to the correct group for your distro: `usermod -aG sudo username` on Ubuntu/Debian, or `usermod -aG wheel username` elsewhere.
3. Log the user out and back in, or run `newgrp sudo` (or `newgrp wheel`) in their current session.

If you don't have access to any privileged account at all, you'll need to boot into single-user/recovery mode or a live USB to reset access from outside the normal login.

### Editing the Sudoers File with visudo

Direct edits to `/etc/sudoers` are risky. Always use `visudo` to prevent syntax errors.

1. Open a terminal
2. Run:

```
sudo visudo
```

3. Scroll to the bottom of the file
4. Add the following line:

```
username ALL=(ALL) ALL
```

5. Save and exit: **Ctrl + X**, **Y**, **Enter**

**Tip:** To make editing easier:

```
export EDITOR=nano
```

### The Better Way: Using /etc/sudoers.d/

Rather than editing the main `/etc/sudoers` file directly, most modern distros support dropping a separate file into `/etc/sudoers.d/`. Anything in that directory is automatically included, and it won't get overwritten by package updates or accidentally conflict with other admin edits.

1. Create a new file named after the user (no dots, no trailing tilde):

```
sudo visudo -f /etc/sudoers.d/username
```

2. Add the same permission line:

```
username ALL=(ALL) ALL
```

3. Save and exit. `visudo` validates this file's syntax the same way it does the main sudoers file.

This is the approach most sysadmins prefer today for anything beyond a quick one-off change, since each user's permissions live in their own file.

## Granting Sudo Access on Other Linux Distributions

The following instructions show how to add a user to the sudoers file on other popular Linux distributions.

### CentOS: Add User to Sudoers (wheel group)

1. Switch to root:

```
su -
```

2. Add the user to the wheel group:

```
usermod -aG wheel username
```

3. Verify sudo access:

```
su - username
sudo whoami
```

### Arch Linux: Add User to Sudoers

1. Install sudo:

```
pacman -S sudo
```

2. Edit the sudoers file:

```
EDITOR=nano visudo
```

3. Uncomment the following line:

```
%wheel ALL=(ALL) ALL
```

4. Add the user to the wheel group:

```
usermod -aG wheel username
```

### Fedora: Add User to Sudoers

Fedora includes sudo by default, and the `wheel` group is already uncommented in `/etc/sudoers`. You only need to add the user to the group.

```
usermod -aG wheel username
```

If you want to double-check the group is active, run `sudo visudo` and confirm this line is uncommented:

```
%wheel ALL=(ALL) ALL
```

### openSUSE: Add User to Sudoers

```
zypper install sudo
usermod -aG wheel username
```

### Gentoo: Add User to Sudoers

```
emerge --ask app-admin/sudo
usermod -aG wheel username
```

## Verifying and Managing Sudo Access

Once a user has been added, confirm it worked and understand what they can actually do.

- **Check current permissions:** `sudo -l` lists every command (or ALL) the logged-in user is allowed to run.
- **Quick root check:** `sudo whoami` should print `root` if access is working.
- **Remove access later:** remove the user from the sudo/wheel group with `deluser username sudo` (Debian/Ubuntu) or `gpasswd -d username wheel` (wheel-based distros), or delete their line from `visudo` if they were added individually.

## Frequently Asked Questions

### What is the sudoers file?

The sudoers file (`/etc/sudoers`) defines which users or groups can run commands with elevated privileges using `sudo`, and under what conditions.

### What's the difference between the sudo group and the wheel group?

They serve the same purpose-granting sudo access to their members-just under different names by convention. Debian and Ubuntu use `sudo`; Fedora, CentOS, Arch, openSUSE, and Gentoo use `wheel`.

### Is using sudo the same as being logged in as root?

No. A sudo user still runs as their own account by default and only gains root privileges for the specific command they prefix with `sudo`, after authenticating with their own password. Being logged in as root grants full privileges to every command run in that session, which is riskier.

### Why should I use visudo instead of editing the file directly?

`visudo` locks the file against simultaneous edits and validates syntax before saving, preventing errors that could break sudo entirely or lock you out of admin access.

### Why am I seeing "username is not in the sudoers file"?

The account has no sudo privileges yet-it isn't in the sudo/wheel group and has no individual entry in `/etc/sudoers`. Add it to the correct group (see above) using an account that already has root or sudo access.

### How do I verify sudo access is working?

Run `sudo whoami` or `sudo -l`. If you see root privileges listed, sudo is working correctly.

### Is it safe to use NOPASSWD in the sudoers file?

Generally no, outside of specific automation or scripting needs. `NOPASSWD` lets a user run sudo commands without entering a password, which removes an important security check-anyone with access to that user's session gets root-level access instantly.

### Can I remove sudo access later?

Yes. Remove the user from the sudo or wheel group, or delete their entry using `visudo` (including any file you created in `/etc/sudoers.d/`).

## Best Practices When Managing Sudo Access

- Always edit sudoers using `visudo`, whether editing the main file or a file in `/etc/sudoers.d/`
- Prefer group based access over individual user entries for most users
- Use `/etc/sudoers.d/` drop-in files instead of the main sudoers file when managing several users individually
- Grant sudo access only to trusted users
- Avoid using `NOPASSWD` unless absolutely necessary for automation

### Final Thoughts

Granting sudo access gives users full administrative control over a Linux system. When done correctly-using groups, `visudo`, and `/etc/sudoers.d/` where it makes sense-it provides both flexibility and security. Follow these steps carefully and you can safely manage user privileges across nearly any Linux distribution.
