Skip to lesson

Linux Command Line · Lesson 22 of 43

Users, groups and who you are

Learn how Linux identifies users and groups, read the output of id, whoami and groups, and find account details in /etc/passwd and /etc/group.

Beginner to intermediate·11 min·Users and permissions·Updated 2026-11-24

UNDERSTAND IT. THEN TRY IT.

What you can do after this lesson

You will know what "who you are" means to Linux, how to check it, and where accounts and groups are recorded. This is the base for permissions: before you can understand who may read, change or run a file, you need to know who the "who" is.

Users and IDs

Linux is a multi-user system, even on a laptop with one person. Every process runs as some user, and every file is owned by some user. The kernel does not use names for this. It uses a number, the user ID or UID. A name such as asha is a label for a UID such as 1000, kept in a table.

Three kinds of accounts exist:

  • root has UID 0 and may do anything. It is the administrator account.
  • System accounts have low UIDs and run services such as web servers or databases. They have no password login.
  • Regular users are real people, with UIDs starting at 1000 on most distributions (500 on some older ones).

Who am I?

whoami prints your user name:

bash
whoami
result
learner

id prints more: your UID, your primary group and every group you belong to. On your own machine the numbers will be different, but the shape is the same:

text
uid=1000(asha) gid=1000(asha) groups=1000(asha),27(sudo),100(users)

id -u prints only the UID, id -un the name, id -gn your primary group name, and groups prints the group names:

bash
id -u > /dev/null && echo "id works"
result
id works

Groups

A group is a named set of users. Groups make it possible to share files without making them public. For example, everyone in a developers group can be given access to a project folder. Every user has one primary group, which is used for the files they create, and may belong to any number of supplementary groups. Two groups come up often:

  • sudo (or wheel on Fedora and Red Hat systems): its members may use sudo.
  • docker: its members may run Docker commands (and effectively have administrator rights).

The account database: /etc/passwd

Accounts live in a plain text file. Each line describes one account, with seven fields separated by colons:

bash
grep "^root:" /etc/passwd
result
root:x:0:0:root:/root:/bin/bash

From left to right: the name, a placeholder x (the real password hash is in the protected /etc/shadow), the UID, the primary GID, a description, the home directory and the login shell. A shell of /usr/sbin/nologin or /bin/false means the account cannot log in interactively. To get the names of all accounts, take the first field:

bash
cut -d: -f1 /etc/passwd | head -n 3
text
root
bin
daemon

The exact accounts depend on the system. Groups follow the same pattern in /etc/group, with the name, a placeholder, the GID and a comma-separated list of members.

Looking up one user

getent passwd NAME asks the system database, including accounts that come from a network directory and do not appear in the local file:

bash
getent passwd root
result
root:x:0:0:root:/root:/bin/bash

Switching and creating users

su (switch user) starts a shell as another user, and sudo runs one command as another user, normally root, which a later lesson covers. Administrators create accounts with useradd or the friendlier adduser, change passwords with passwd and remove accounts with userdel. These need root rights, and they change the system, so we only show their shape:

text
sudo adduser maria
sudo usermod -aG sudo maria

The -aG option appends to the groups. Forgetting -a replaces all the user's supplementary groups, a common and painful mistake.

Why this matters for security

Because everything has an owner, a normal user cannot read another user's private files or change system files. A program you run has your rights, and no more. That is why you should work as a normal user and use administrator rights only for the single command that needs them.

Common mistakes

Working as root all the time. One typo as root can break the system. Use a normal account.

Confusing user names and UIDs. If a user is renamed or an account is recreated with a different UID, files may seem to belong to a number.

Editing /etc/passwd by hand. Use useradd, usermod and friends, which keep the files consistent.

Forgetting -a in usermod -G. It removes the user from the other groups.

Exercise

On your machine, run whoami, id and groups. Write down your UID and your groups. Find your own line in /etc/passwd with grep "^$(whoami):" /etc/passwd and name its seven fields. Check whether you are in the sudo or wheel group.

KNOWLEDGE CHECK

A quick check. You’ve got this.

Try each question. Every answer comes with an explanation.

0 / 4 understood
01 What does the kernel actually use to identify a user?
02 Which command shows your user ID, group ID and all your groups?
03 What is the UID of the root user?
04 Which file lists the user accounts on the system?

Ready for the next small win?

Mark the lesson complete when you are ready.

Course navigation

Tools and Workflow

Linux Command Line tutorial

Learn to work confidently in the terminal, from your first command to pipes, permissions, scripts and a real log-analysis project.

Your progress 0/43
Learning something new?Explore all courses