Skip to content

Linux basicsFor beginnersDuration around 10 min.

How to create a user in Linux, grant sudo and add it to a group

If you work as root every day, a single typo can affect the entire server. This tutorial creates a dedicated user, grants them sudo rights and shows how groups regulate shared access to folders.

Tested on with Ubuntu 24.04 LTS with sudo 1.9 and Ubuntu 26.04 LTS with sudo-rs 0.2

At a glance

  • sudo adduser anna creates the user, group and home directory and asks for the password.
  • sudo usermod -aG sudo anna grants sudo rights — the -a is important, without it the user loses all other groups.
  • New groups only take effect after the user signs in again.

Prerequisites

  • A server with Ubuntu 24.04 or 26.04 and access as root or with sudo — such as a VPS or a Cloud Server.

In the examples, the new user is called anna, the group entwickler.

1. Create a user

On Ubuntu, adduser is the convenient way: it creates the user, a group of the same name and the home directory, asks for the password and optionally for a name and phone number — these fields can be left blank.

Create a user
sudo adduser anna

useradd is the simpler tool available on every Linux distribution. Without -m it does not create a home directory, without -s the user gets a basic shell; you set the password afterwards with passwd.

The same with useradd
sudo useradd -m -s /bin/bash anna
sudo passwd anna

2. Grant rights for sudo

Anyone belonging to the sudo group can execute commands as root, after entering their own password.

Add to the sudo group
sudo usermod -aG sudo anna
groups anna
Output of groups
anna : anna sudo users

Sign in as anna and check the rights. If root is in the output afterwards, sudo is working. On Ubuntu 26.04, sudo-rs responds, the new version of sudo; the commands remain the same.

Check rights
su - anna
sudo whoami

3. Create a group and add a user

Create and assign a group
sudo groupadd entwickler
sudo usermod -aG entwickler anna
getent group entwickler
Members of the group
entwickler:x:1002:anna

Always -aG, never -G alone

usermod -G without -a replaces all additional groups with the specified one. In the example below, anna loses the sudo group — and thus her rights.
Not like this
sudo usermod -G entwickler anna
groups anna
The sudo group is missing
anna : anna entwickler

4. Shared folder for a group

If a folder belongs to the group and has the set-GID bit, the 2 before 775, then all new files in it also belong to the group. This allows all members to edit each other's files.

Folder for the group
sudo mkdir -p /srv/projekt
sudo chgrp entwickler /srv/projekt
sudo chmod 2775 /srv/projekt
ls -ld /srv/projekt
The s shows the set-GID bit
drwxrwsr-x 2 root entwickler 4096 Dec  2 10:31 /srv/projekt

5. Remove from a group, lock and delete

gpasswd removes a user from a single group without affecting the others:

Remove from the group
sudo gpasswd -d anna entwickler

A user who should temporarily no longer work is locked; userdel permanently removes them along with their home directory. Back up their files beforehand if you still need them.

Lock and delete
sudo passwd -l bernd
sudo userdel -r bernd

Typical errors

  • No access with sudo despite group: Groups are read during sign-in. Sign out and sign in again.
  • Other groups are gone: usermod was called with -G instead of -aG. Add the missing groups again with -aG.
  • No home directory: useradd ran without -m. Create the directory and hand it over to the user, or delete and recreate the user with adduser.
  • User is still signed in: Terminate their processes or lock them first and delete them later.

We tested all commands in this guide on 2 December 2026 — with Ubuntu 24.04 LTS with sudo 1.9 and Ubuntu 26.04 LTS with sudo-rs 0.2. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about users and groups

What is the difference between adduser and useradd?

useradd is the basic tool of every Linux distribution and only does what the options say. adduser is a more convenient wrapper on Debian and Ubuntu that handles the home directory and password at the same time.

Why doesn't a new group take effect immediately?

A user's groups are read at sign-in. Only after signing out and signing back in does the current session belong to the new group.

How do I show a user's groups?

With groups and the username, or in more detail with id; conversely, getent group shows all members of a group.

Is the group for sudo called sudo everywhere?

On Debian and Ubuntu, yes. Other distributions like Rocky Linux or AlmaLinux use the wheel group for this.

Should I work directly as root?

Better not. A dedicated user with sudo shows in the logs who did what, and protects against commands accidentally running as root.

Further reading

More tutorials

  • The scp command with examples: copy files over SSH

    Linux basicsFor beginnersabout 5 min

    scp copies files over an SSH connection — encrypted, with the same credentials as your login, and without an additional service on the server. This guide shows the commands for common use cases, each with an example to copy.

  • How to check your Ubuntu version, codename and kernel

    Linux basicsFor beginnersabout 2 min

    A single command in the terminal shows which Ubuntu version is running on a server. Here are the common ways with their output — for the version with point release, the codename, the kernel and the architecture.

  • How to remove a directory in Linux with rm and rmdir

    Linux basicsFor beginnersabout 5 min

    In Linux, you delete an empty folder with rmdir and a folder including its contents with rm -r. This tutorial shows both commands with their messages, the variants with and without prompting, and what to check before running rm -rf — because there is no recycle bin in the terminal.

A server for your team

On a VPS, you create a separate access for each person, with sudo only for those who need it.