How to Create a User and Grant Sudo in Linux

11 Mar 2026 By Roman Sokolov

Password generator

A cryptographically strong password is generated in your browser and never sent anywhere.

To create a user with administrator rights in Linux you need two commands: adduser to create the account and usermod -aG to add it to the sudo group. Let’s go through it in detail, including the differences between distributions.

Step 1. Create the user

On Debian and Ubuntu the handiest option is adduser — an interactive utility that creates the home directory and asks for a password:

sudo adduser deploy

The command asks for a password and optional details (full name, phone — you can skip them by pressing Enter).

On distributions without adduser, use the low-level useradd:

sudo useradd -m -s /bin/bash deploy
sudo passwd deploy

The -m flag creates the home directory, -s sets the shell.

Step 2. Grant sudo rights

Administrative rights come from membership in a special group.

Debian / Ubuntu — the sudo group:

sudo usermod -aG sudo deploy

CentOS / RHEL / Fedora — the wheel group:

sudo usermod -aG wheel deploy

The flags matter: -a (append) adds the group without removing the existing ones. Without -a the user is dropped from every other group — a very common mistake.

Step 3. Check the rights

Log in as the new user and run a test command:

su - deploy
sudo whoami

If it returns root, the rights work. To see all groups of a user:

groups deploy

Granting narrow rights through sudoers

Sometimes you want to allow a user only specific commands instead of full sudo. Use the safe visudo editor, which validates the syntax:

sudo visudo -f /etc/sudoers.d/deploy

Add a line — for example, allowing only an nginx restart:

deploy ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx

NOPASSWD removes the password prompt for that command. Files in /etc/sudoers.d/ are picked up automatically.

How to revoke sudo rights

Remove the user from the sudo group:

sudo deluser deploy sudo

On CentOS:

sudo gpasswd -d deploy wheel

Deleting a user

If the account is no longer needed, delete it together with the home directory:

sudo deluser --remove-home deploy

Distribution comparison

Action Debian/Ubuntu CentOS/RHEL
Create adduser useradd -m
Admin group sudo wheel
Grant rights usermod -aG sudo usermod -aG wheel
Revoke deluser user sudo gpasswd -d user wheel

Frequently asked questions

How does adduser differ from useradd? adduser is a friendly interactive script (creates the home directory, asks for a password). useradd is a low-level utility that needs the flags spelled out. On Ubuntu both are available.

Why is usermod without -a dangerous? The -G flag without -a replaces the user’s entire group list with what you specify. Forget -a and the user loses membership in every other group. Always write -aG.

How do I allow sudo without a password? Add a line with NOPASSWD to a file in /etc/sudoers.d/. Do it only for trusted accounts and specific commands — it lowers security.

Do group changes apply immediately? You have to log in again. A new session sees the updated group list; the current one does not.

Summary

Creating a user with sudo is a basic step when setting up any server. Remember the difference between the sudo and wheel groups across distributions, and always use -aG so you do not wipe the remaining groups.

Need a server to practise on? Take a Linux VPS, order VPS hosting, or order Server administration.

Roman Sokolov