Users, groups and sudo on openSUSE, Fedora and Ubuntu

Create users, share files through groups, and set up sudo the way your distribution expects.

Part 6 of 12 in Linux basics for self-hosters. Last updated

In short: Create a user with sudo useradd -m alice and set a password with sudo passwd alice. Add a user to a group with sudo usermod -aG groupname alice; without -a you replace all their other groups. The admin group is sudo on Debian and Ubuntu and wheel on Fedora, while openSUSE by default asks for the root password on sudo. For rootless podman services, use a normal user with lingering enabled.

Who am I, and in which groups?

id                       # uid=1000(alice) gid=1000(alice) groups=1000(alice),477(wheel)
groups alice             # just the group names
getent group wheel       # who is in the wheel group
getent passwd alice      # home directory and login shell

Every user has a number (UID) and a primary group; the kernel only cares about the numbers. Regular users start at 1000. The users below 1000 are system accounts that run services. getent reads the same databases the system uses, so it also works when accounts come from somewhere other than /etc/passwd.

One line per user in /etc/passwd, and the sub-UID range rootless podman borrows from /etc/subuid.

On an openSUSE laptop that kept the default sudo policy, the wheel group exists but is empty; why is explained under sudo per distribution:

$ id
uid=1000(user) gid=1000(user) groups=1000(user),459(vboxusers)

$ getent passwd root nobody; getent group wheel
root:x:0:0:root:/root:/bin/zsh
nobody:x:65534:65534:nobody:/var/lib/nobody:/usr/sbin/nologin
wheel:x:477:

Real output on openSUSE Tumbleweed, 2026-09-28; user and host names and addresses redacted.

Creating and removing users

sudo useradd -m -s /bin/bash alice    # -m: create /home/alice
sudo passwd alice                     # set a password
sudo userdel -r alice                 # remove the user and the home directory

useradd works the same on every distribution. Debian and Ubuntu also ship adduser, a friendlier script that asks questions and creates the home directory for you. Think twice before userdel -r: the home directory is gone, and there is no trash can. The options are in useradd(8).

Groups: sharing without chmod 777

Say two users and a media server container all need the same folder. Create a group, put everyone in it, and give the folder to the group:

sudo groupadd media
sudo usermod -aG media alice
sudo usermod -aG media bob
sudo chown -R alice:media /srv/media
sudo chmod 2775 /srv/media            # 2 = setgid: new files get the media group
sudo gpasswd -d bob media             # later: remove bob from the group again

The -a in usermod -aG means append. Without it, -G sets the list of groups and removes the user from every group you did not name. Membership takes effect at the next login. What the modes mean is explained in the file permissions guide, and the chmod calculator translates 2775 for you.

sudo per distribution

sudo command runs one command as root and logs it. Which users may do that is set in the sudoers configuration, and the defaults differ:

Who may use sudo after a default installation
DistributionAdmin groupPassword askedMake alice an admin
Debian, UbuntusudoYour ownsudo usermod -aG sudo alice
FedorawheelYour ownsudo usermod -aG wheel alice
openSUSE (default)Noneroot's passwordAnyone who knows the root password can use sudo
openSUSE with the wheel policywheelYour ownsudo zypper in sudo-policy-wheel-auth-self, then sudo usermod -aG wheel alice

openSUSE's default comes from Defaults targetpw in /usr/etc/sudoers: sudo asks for the password of the target user, which is root. For your own rules, never edit the main file. Create a drop-in with visudo, which checks the syntax before saving, so a typo cannot lock you out:

# openSUSE Tumbleweed: sudo asks for root's password
$ grep -E '^[^#]*targetpw' /usr/etc/sudoers
Defaults targetpw   # ask for the password of the target user i.e. root

# Debian 12: admins are the members of the sudo group
$ getent group sudo
sudo:x:27:user

Real output on openSUSE Tumbleweed and Debian 12, 2026-09-28; user and host names and addresses redacted.

sudo visudo -f /etc/sudoers.d/alice
# contents, one line:
# alice ALL=(ALL:ALL) ALL
sudo visudo -c                        # check every sudoers file

The rule syntax is documented in sudoers(5). Need a root shell for a longer job? sudo -i, and exit as soon as you are done.

Users for services and rootless podman

A service that runs as root can do anything when it is compromised. Two better options:

  • A system user for a classic daemon: sudo useradd --system --no-create-home --shell /usr/sbin/nologin backupd, then User=backupd in its systemd unit.
  • A normal user for rootless podman, which needs a home directory and a range of sub-UIDs. useradd adds that range to /etc/subuid and /etc/subgid automatically on current distributions; check with grep alice /etc/subuid.
grep alice /etc/subuid /etc/subgid      # alice:100000:65536 in both
sudo loginctl enable-linger alice       # user services start at boot, keep running after logout
# log in as alice over SSH (not with su or sudo -u), then:
systemctl --user status

Both checks on a working rootless podman account:

$ grep "^$(id -un):" /etc/subuid /etc/subgid
/etc/subuid:user:100000:65536
/etc/subgid:user:100000:65536

$ loginctl show-user $(id -un) -p Linger
Linger=yes

Real output on openSUSE Tumbleweed, 2026-09-28; user and host names and addresses redacted.

systemctl --user needs a real login session. su alice and sudo -u alice do not create one, so they fail with "Failed to connect to bus". Log in over SSH, or use sudo machinectl shell alice@ (package systemd-container). The SSH key and config helper sets up key login for that user in a few steps.

Common mistakes

usermod -G without -a

sudo usermod -G media alice makes media alice's only extra group; she drops out of wheel or sudo and loses her admin rights. Always write -aG. If it already happened, fix it from another admin account or a root shell.

alice is not in the sudoers file. This incident will be reported.

The user is not in the admin group, or has not logged in again since being added. Check with id alice. On openSUSE with the default policy you will not see this message, because every user may run sudo with root's password; "Sorry, try again" there means you typed your own password instead of root's.

Editing /etc/sudoers with a normal editor

One syntax error and sudo refuses to run at all, including the sudo you need to fix it. Use visudo, and keep changes in /etc/sudoers.d/, where a broken file is easy to find and remove from a root shell.

Frequently asked questions

How do I add a user to sudoers on openSUSE?

openSUSE's default sudo configuration asks for the root password (Defaults targetpw), so any user who knows it can use sudo. To use your own password like on Fedora, install the sudo-policy-wheel-auth-self package and add yourself to wheel with sudo usermod -aG wheel alice, then log in again.

Why does my new group not work after usermod -aG?

Group membership is read at login. Log out and back in (or reconnect over SSH), then check with id. For a quick test in the current shell, newgrp groupname starts a subshell with the new group.

What is the difference between sudo -i and sudo su?

Both give you a root shell. sudo -i is the direct way: it starts root's login shell with root's environment and is logged by sudo. sudo su runs a second program to do the same thing. Prefer sudo with a single command over a root shell whenever you can.

What does useradd -m do?

-m creates the home directory (/home/alice) and copies the default files from /etc/skel into it. Some distributions do this by default through CREATE_HOME in login.defs, but passing -m makes the command behave the same everywhere.