Users and groups: /etc/passwd, /etc/group, id
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- The system knows a user not by name but by UID (a number); root's UID is 0.
/etc/passwdholds users,/etc/shadowthe password hashes (only root can read it),/etc/groupthe groups.- On Ubuntu regular users start at UID 1000; those below are service accounts (
www-data,sshd). - Every user has one primary group and can have several supplementary groups.
id,whoami,groups,whoanswer "who am I and who is on the server?".
Why users are needed
A server runs several admins, a web server and a database. When each runs as a separate user, one cannot touch the files of another. For example, nginx runs as www-data: even if the site is hacked, the attacker does not become root and can only reach what www-data is allowed to.
Who am I?
ali@srv-web01:~$ whoami ali ali@srv-web01:~$ id uid=1000(ali) gid=1000(ali) groups=1000(ali),4(adm),27(sudo)
id shows three things:
| Part | Meaning |
|---|---|
uid=1000(ali) | The user's number and name |
gid=1000(ali) | The primary group — files you create belong to it |
groups=... | All groups; sudo gives admin rights, adm lets you read logs |
/etc/passwd
Each line is one user, with fields separated by ::
ali@srv-web01:~$ grep -E "^(root|www-data|ali):" /etc/passwd root:x:0:0:root:/root:/bin/bash www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin ali:x:1000:1000:Ali,,,:/home/ali:/bin/bash
| Field | Example | Meaning |
|---|---|---|
| 1 | ali | Name |
| 2 | x | The password is in /etc/shadow |
| 3 | 1000 | UID |
| 4 | 1000 | GID of the primary group |
| 5 | Ali,,, | Comment (full name) |
| 6 | /home/ali | Home directory |
| 7 | /bin/bash | Login shell |
An account whose shell is /usr/sbin/nologin cannot log in to a terminal — service accounts are like this.
UID ranges (Ubuntu)
| UID | Who |
|---|---|
| 0 | root — allowed everything |
| 1–999 | System and service accounts |
| 1000 and above | Regular users |
| 65534 | nobody — an account with no rights |
/etc/shadow and /etc/group
Password hashes are in /etc/shadow, and only root can read it:
ali@srv-web01:~$ cat /etc/shadow cat: /etc/shadow: Permission denied ali@srv-web01:~$ grep -E "^(sudo|adm|www-data):" /etc/group adm:x:4:syslog,ali sudo:x:27:ali www-data:x:33:
In /etc/group the last field lists the group's supplementary members. Only ali is in the sudo group, so only they can run admin commands.
Who is on the server?
ali@srv-web01:~$ who ali pts/0 2026-12-01 09:14 (10.20.0.5) ali@srv-web01:~$ last -n 3 ali pts/0 10.20.0.5 Tue Dec 1 09:14 still logged in ali pts/0 10.20.0.5 Mon Nov 30 17:02 - 18:40 (01:38) reboot system boot 6.8.0-49-generic Mon Nov 30 08:55 still running
who shows who is connected now and last shows recent logins. A login from an IP you do not recognise is a security signal.
Try id, groups and cat /etc/passwd in the Linux simulator.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1What does the system actually use to identify a user?
2What is root's UID?
3Where are password hashes stored?
/etc/passwd only contains x; the hashes are in /etc/shadow, which only root can read.4What does the /usr/sbin/nologin shell mean?
5Which command shows the UID, primary group and all groups together?
whoami shows only the name, who the connected users, last recent logins.Comments
Sign in to comment.