> ## 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 Create a Sudo User on Ubuntu, Debian and AlmaLinux

> Create a sudo user on Ubuntu or Debian with adduser and the sudo group, or on AlmaLinux and Rocky with useradd and the wheel group, then copy your SSH key.

To create a sudo user on Ubuntu, run `sudo adduser alex` and then `sudo usermod -aG sudo alex`. Debian works the same way. On AlmaLinux and Rocky Linux the admin group is `wheel`: run `sudo useradd -m alex`, `sudo passwd alex` and `sudo usermod -aG wheel alex`. Log in as the new user and run `sudo whoami`; it prints `root`.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 5 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10 | Root access |

## Before you start

* [Connect with SSH](https://help.freakhosting.com/portals/other/how-to-connect-to-a-linux-server-with-ssh.md) as `root` (or an existing sudo user). As root you can leave `sudo` out of the commands below.
* Choose a user name in lower case, for example `alex`.

## Why use a sudo user instead of root?

`root` can do anything, with no confirmation. A normal user with **sudo** rights works without admin power and only becomes root for one command at a time when you type `sudo`. Mistakes are less likely, every `sudo` command is logged, and you can later [disable root login over SSH](https://help.freakhosting.com/portals/other/how-to-disable-root-login-over-ssh.md).

## How to create a sudo user

> [tab] Ubuntu / Debian
>
> **1. Create the user**
>
> ```bash theme={null}
> sudo adduser alex
> ```
>
> Enter a strong password twice. The name and phone fields are optional: press `Enter` to skip them, then `Y`. `adduser` creates the home directory `/home/alex` for you.
>
> **2. Add the user to the sudo group**
>
> ```bash theme={null}
> sudo usermod -aG sudo alex
> ```
>
> `-a` (append) is important. Without it, `-G` replaces all the user's other groups.
>
> **3. Check the groups**
>
> ```bash theme={null}
> groups alex
> ```
>
> Expected output:
>
> ```text theme={null}
> alex : alex sudo
> ```
>
> > [!NOTE]
> >
> > Some minimal Debian installs don't include `sudo`. If you see `sudo: command not found`, install it as root first: `apt install sudo`.

> [tab] AlmaLinux / Rocky
>
> **1. Create the user**
>
> ```bash theme={null}
> sudo useradd -m alex
> ```
>
> **2. Set a password**
>
> ```bash theme={null}
> sudo passwd alex
> ```
>
> **3. Add the user to the wheel group**
>
> ```bash theme={null}
> sudo usermod -aG wheel alex
> ```
>
> On AlmaLinux and Rocky Linux, members of `wheel` can use sudo because `/etc/sudoers` contains the line `%wheel  ALL=(ALL)  ALL`.
>
> **4. Check the groups**
>
> ```bash theme={null}
> groups alex
> ```
>
> Expected output:
>
> ```text theme={null}
> alex : alex wheel
> ```

## How to let the new user log in with your SSH key

If you log in to root with an [SSH key](https://help.freakhosting.com/portals/other/how-to-create-and-use-ssh-keys.md), copy the key to the new user so you can log in without a password. Run as root:

```bash theme={null}
mkdir -p /home/alex/.ssh
cp /root/.ssh/authorized_keys /home/alex/.ssh/
chown -R alex:alex /home/alex/.ssh
chmod 700 /home/alex/.ssh
chmod 600 /home/alex/.ssh/authorized_keys
```

The strict permissions matter: SSH ignores an `authorized_keys` file that other users can write to.

## How to check it worked

> [!WARNING]
>
> Keep your current root session open. Test the new user in a **second** terminal before you log out or change any SSH settings, so you can fix mistakes if the login fails. If you get locked out of a VPS, use the [VNC console](https://help.freakhosting.com/portals/vps-panel/how-to-enable-and-use-vnc-console-access.md).

**1. Log in as the new user**

```bash theme={null}
ssh alex@203.0.113.10
```

**2. Test sudo**

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

Enter **alex's** password (not root's). Expected output:

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

`sudo -l` lists what the user is allowed to run. For a full admin it shows `(ALL : ALL) ALL`.

## How to give sudo without a password (optional)

For automation accounts you can allow sudo without a password. Always edit sudo rules with `visudo`, which checks the syntax before saving; a broken sudoers file can stop every user from using sudo.

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

Add this line, save and exit:

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

File names in `/etc/sudoers.d/` must not contain a dot or end with `~`, or sudo ignores them. Check all files with `sudo visudo -c`.

> [!WARNING]
>
> Passwordless sudo means anyone who gets into that account is instantly root. Use it only for accounts that log in with SSH keys.

## Frequently asked questions

### What is the difference between `adduser` and `useradd`?

On Ubuntu and Debian, `adduser` is a friendly script that asks for a password and creates the home directory. `useradd` is the low-level tool on every distribution; it needs options such as `-m` for the home directory and a separate `passwd` command. On AlmaLinux and Rocky, `adduser` is the same as `useradd`.

### Why does sudo say "alex is not in the sudoers file"?

The user is not in the `sudo` group (Ubuntu/Debian) or `wheel` group (AlmaLinux/Rocky), or you haven't logged in again since adding them. Group changes apply at the next login.

### How do I remove sudo rights from a user?

Run `sudo gpasswd -d alex sudo` on Ubuntu/Debian or `sudo gpasswd -d alex wheel` on AlmaLinux/Rocky, and delete any file for that user in `/etc/sudoers.d/`.

### Can I log in to my VPS as root after this?

Yes, until you turn it off. Once your sudo user works, you can [disable root login over SSH](https://help.freakhosting.com/portals/other/how-to-disable-root-login-over-ssh.md). Keep a way back in: the VPS Panel can [reset the root password](https://help.freakhosting.com/portals/vps-panel/how-to-reset-your-vps-root-password.md).

## Related guides

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

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

> [card] [Create and use SSH keys](https://help.freakhosting.com/portals/other/how-to-create-and-use-ssh-keys.md)
>
> Log in without passwords.

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

> [card] [Fix sudo errors](https://help.freakhosting.com/portals/other/how-to-fix-sudo-command-not-found-and-permission-errors.md)
>
> When sudo doesn't work.

***

> [!NOTE]
>
> **Checked against the official [Red Hat Enterprise Linux 9 documentation on managing sudo access](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html/configuring_basic_system_settings/managing-sudo-access_configuring-basic-system-settings)** and the `adduser`, `usermod` and `sudoers` man pages on 4 November 2026; Ubuntu/Debian commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

> [!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.