COMP 3150Operating Systems

01 Introduction

Every file you create, every process you run, and every system resource you touch has an owner: the user account under which the operation was performed. Linux tracks this identity at every level, from the read() system call that opens a file to the kill() call that signals a process. The result is a system that can support multiple simultaneous users, enforce separation between them, and apply different policies depending on who is asking.

Users are not the only unit of identity. Every user belongs to one or more groups — collections of accounts that share access to the same resources. Groups allow you to grant access not to individuals but to roles: everyone in the developers group gets write access to the source repository, everyone in the sudo group can run commands as root, everyone in the docker group can manage containers. This is far easier to administer than managing per-user permissions one at a time.

This lesson covers the user account model, the group model, the tools for managing both, the distinction between root and ordinary users, and the discipline of privilege separation that determines when and how elevated privileges should be used. The lesson that follows will show how these identities translate into specific access decisions on files and other resources.

02 Learning objectives

By the end of this lesson you will be able to

  • Explain user accounts.
  • Explain groups and roles.
  • Manage accounts.
  • Explain privilege separation.
  • Apply secure administration practices.

This lesson contributes to U2.3 and to course learning outcomes CLO6 and CLO7.

03 Required reading

  • Stevens & Rago — Advanced Programming in the UNIX Environment, 3rd ed., Section 1.7 (users and groups) and Section 4.4 (file ownership, briefly). The classical presentation of the user/group model and how the kernel uses it.
  • Linux man pages: man 5 passwd, man 5 group, man 5 shadow, man 8 useradd, man 8 groupadd, man 8 sudo, man 7 capabilities. These are the definitive reference for the account model.
  • Nemeth, E., Snyder, G., Whaley, B., & Mackin, D. — UNIX and Linux System Administration Handbook, 5th ed., Chapters 6 (managing users) and 8 (access control). An authoritative survey of administration practice.

Reading strategy

Read Stevens & Rago Section 1.7 first for the conceptual model, then the man pages for passwd, group, and shadow — they describe the exact file formats the kernel and login programs consult. You do not need to memorise the field meanings; you need to know they exist and where to find them when you need to look something up.

04 Core content

4.1 What a user account is

A user account is a record that identifies a principal on the system. Each account has:

Username
A human-readable name, such as alice or deploy. Usernames are what you type at a login prompt, but they are not what the kernel uses for access decisions.
User ID (UID)
A non-negative integer that uniquely identifies the account to the kernel. The UID is what appears in the ownership field of every file and process. The username is a convenience for humans; the UID is the real identity.
Primary group
The group ID (GID) that the account belongs to by default. Every file the user creates will be owned by this group unless changed.
Home directory
The directory the user starts in when they log in. Conventionally /home/<username> for ordinary users, /root for the root account.
Login shell
The program that runs when the user logs in interactively. Usually /bin/bash or /bin/sh for human accounts, or /usr/sbin/nologin for accounts that exist for system purposes and should not be logged into.
Password hash
The hash of the user's password, stored separately from the other account information (see below). Empty or locked for accounts that do not authenticate interactively.

4.2 The account databases

Linux stores account information in a small number of text files. Historically all account data was in a single file; today it is split across several for security and flexibility.

The main account databases on Linux
File Purpose Readable by
/etc/passwd User account information: username, UID, GID, home directory, shell Everyone (world-readable)
/etc/shadow Password hashes and password-aging policy Root only (mode 0640, group shadow)
/etc/group Group names, GIDs, and members Everyone
/etc/gshadow Group passwords (rarely used) and administrators Root only
/etc/login.defs Defaults for account creation (UID ranges, password policy) Everyone

4.3 The format of /etc/passwd

Each line in /etc/passwd describes one account, with seven fields separated by colons:

username:password:UID:GID:GECOS:home:shell

alice:x:1000:1000:Alice Example,,,:/home/alice:/bin/bash
root:x:0:0:root:/root:/bin/bash
sshd:x:105:65534::/run/sshd:/usr/sbin/nologin

Interpreting the fields in the first line:

  • alice — the username.
  • x — a placeholder. The actual password hash is stored in /etc/shadow. Before shadow passwords were introduced, the hash was here — but because /etc/passwd must be world-readable (many programs need to resolve usernames to UIDs), leaving the hash visible to every user was a serious problem.
  • 1000 — the UID. On most modern Linux distributions, human accounts start at UID 1000, system accounts use UIDs below 1000, and the root account is UID 0.
  • 1000 — the primary GID. The group with this GID is the user's default group.
  • Alice Example,,, — the GECOS field, traditionally holding the user's full name and other information. Subfields are separated by commas; the field is often left empty.
  • /home/alice — the home directory.
  • /bin/bash — the login shell.

4.4 The format of /etc/shadow

/etc/shadow holds the password hash and password-aging information. Each line has nine fields:

username:hash:last_change:min:max:warn:inactive:expire:reserved

alice:$6$Xk2p9qR3$eHk8...:19645:0:99999:7:::
  • username — matches the entry in /etc/passwd.
  • hash — the password hash. The format is $algorithm$salt$hash. Common algorithm identifiers: $1$ MD5 (obsolete), $5$ SHA-256, $6$ SHA-512, $y$ yescrypt. A value of ! or * means the account has no usable password and cannot log in with one.
  • last_change — days since Jan 1, 1970 that the password was last changed.
  • min — minimum days before the password may be changed again.
  • max — maximum days before the password must be changed.
  • warn — days before expiry that the user is warned.
  • inactive — days after expiry before the account is disabled.
  • expire — days since Jan 1, 1970 that the account itself expires.

Never edit /etc/shadow by hand

The shadow file format is easy to get wrong, and a mistake can lock you out of the system entirely — or worse, silently corrupt the account. Always use the provided tools: passwd to change passwords, chage to change aging policy, usermod to modify accounts. These tools handle the file locking, validation, and format details for you.

4.5 The format of /etc/group

Groups are stored in /etc/group, with four fields per line:

groupname:password:GID:members

sudo:x:27:alice,bob
developers:x:1001:alice,carol,dave
alice:x:1000:
  • sudo — the group name.
  • x — a placeholder; group passwords are stored in /etc/gshadow and are rarely used.
  • 27 — the group's GID.
  • alice,bob — a comma-separated list of users who belong to this group in addition to their primary group.

Note that a user's group membership has two sources:

  • Primary group. Recorded as the GID field in /etc/passwd. Every user has exactly one primary group.
  • Supplementary groups. Recorded in the members field of /etc/group. A user can belong to any number of supplementary groups.

4.6 UID and GID numbering

Different ranges of UIDs are conventionally used for different purposes:

Conventional UID and GID ranges on Linux
Range Purpose
0Root. Exactly one account should have UID 0.
1–999System accounts — daemons and services that do not correspond to a human user.
1000–59999Ordinary human users.
60000–65533Reserved for special purposes.
65534nobody — the account used by services that need to run with essentially no privileges.

These are conventions, not enforced by the kernel — but utilities such as useradd follow them by default, and many programs rely on the assumption that ordinary users have UIDs ≥ 1000 and system accounts have UIDs < 1000.

4.7 Root and privilege separation

The user with UID 0 is root, the superuser. Root bypasses the ordinary permission checks: it can read, write, and execute any file regardless of the permission bits; it can signal any process; it can mount file systems, load kernel modules, reconfigure network interfaces, and change any user's password. The kernel recognises root not by the name "root" but by the numeric UID 0.

Root is necessary — someone has to administer the system — but it is also dangerous. An accidental rm -rf / as root will destroy the machine; a compromised process running as root compromises the entire system; a bug in a setuid-root program is a privilege-escalation vulnerability. The security literature contains a well-known statement of the problem:

The only safe way to run a program is with no privileges at all. The second-safest way is to run it as root, because at least you know exactly what you are doing — everything can go wrong.

The practical response is privilege separation: use root privileges only when they are needed, for the shortest possible time, and by the fewest possible processes. Three mechanisms implement this on Linux:

Three mechanisms for privilege separation Three columns describe the three mechanisms: sudo (temporary elevation on demand), setuid (a binary runs with the owner's privileges), and capabilities (a program holds specific capabilities rather than full root). Each is accompanied by a small diagram and a description of its trade-offs. THREE MECHANISMS FOR PRIVILEGE SEPARATION SUDO temporary elevation, on demand alice (uid 1000) authenticate sudo helper (setuid root) command runs as root Advantages • per-user, per-command policy • logged and auditable • can require a password Trade-offs • the command runs as full root • policy file is easy to misconfigure SETUID binary runs as the file's owner alice executes /usr/bin/passwd kernel sets euid = 0 process runs as root Advantages • no administrator action needed • user runs the tool directly • fine control per tool Trade-offs • every setuid binary is a target • grants full root, not the minimum CAPABILITIES the disaggregated root binary has cap_net_bind any user runs the binary holds only that capability Advantages • precise: only what's needed • no full root privileges • smaller blast radius if buggy Trade-offs • capability model is complex • some caps are still broad Modern practice prefers capabilities when possible, sudo for administrative work, and setuid only when neither alternative is available.
Figure 2.3 — Three mechanisms for privilege separation. Sudo is temporary elevation on demand; setuid grants the file owner's full privileges; capabilities grant specific privileges only.

sudo — temporary elevation on demand

sudo lets an authorised user run a specific command as another user (by default, root). The user authenticates with their own password, and the command runs with elevated privileges. What the user may run is defined in /etc/sudoers (or files under /etc/sudoers.d/), and every invocation is logged.

# Run a single command as root
$ sudo apt update

# Run an interactive shell as root (be careful)
$ sudo -i

# Run as a different user
$ sudo -u postgres psql

# Show what commands you are permitted to run
$ sudo -l

Advantages. Per-user, per-command policy. Every use is logged. The user does not need to know the root password. Most importantly, it makes privilege elevation an explicit, deliberate act rather than a standing state.

Limitations. The command still runs with full root privileges (unless capabilities are used, see below). And the sudoers configuration is a frequent source of security bugs when written carelessly.

setuid — a binary runs as the file's owner

A file with the setuid bit set runs with the effective UID of its owner, not of the user who invoked it. When the owner is root (as it typically is), this gives the running process root privileges. The classic example is /usr/bin/passwd: an ordinary user runs it to change their password, and it needs root privileges to update /etc/shadow.

$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68208 ... /usr/bin/passwd
    ^
    setuid bit

Advantages. No administrator involvement required for the user to run the tool; the setuid binary is the tool itself.

Limitations. Setuid binaries are a classic privilege-escalation target. Any bug in them — a buffer overflow, a path-traversal error, a failure to sanitise the environment — can give an attacker root. Modern practice minimises the number of setuid binaries installed, and when possible replaces them with capabilities.

Capabilities — the disaggregated root

Instead of granting a binary all of root's privileges, capabilities grant a specific subset. A program that only needs to bind to a privileged port can be given CAP_NET_BIND_SERVICE and nothing else. A program that only needs to send raw packets can be given CAP_NET_RAW. This is the least-privilege principle applied to privilege elevation.

$ sudo setcap cap_net_bind_service=+ep /usr/local/bin/myserver
$ getcap /usr/local/bin/myserver
/usr/local/bin/myserver cap_net_bind_service=ep

Advantages. Precisely scoped. A compromised binary holds only the capabilities it was given, not all of root. The blast radius of a vulnerability is much smaller.

Limitations. The capability model has around 40 capabilities, some of which (CAP_SYS_ADMIN in particular) are very broad. Administering capabilities correctly requires understanding them in detail. Capabilities are covered in more depth in Lesson 12.5.

4.8 Managing accounts

The tools for managing accounts fall into four groups: users, groups, membership, and password policy.

Creating and modifying users

# Create a user with a home directory and default shell
$ sudo useradd -m -s /bin/bash alice

# Set the user's password
$ sudo passwd alice
New password:
Retype new password:
passwd: password updated successfully

# Add user information to the GECOS field
$ sudo usermod -c "Alice Example" alice

# Add alice to a supplementary group
$ sudo usermod -aG developers alice

# Lock an account (prevent password login)
$ sudo usermod -L alice

# Remove a user and their home directory
$ sudo userdel -r alice

The -a flag in usermod -aG

The usermod -G option sets the user's supplementary groups to exactly the groups listed, replacing any existing memberships. Combined with -a (append), the user is added to the group without losing other memberships. Always write usermod -aG, not usermod -G, when you mean "add to a group".

Managing groups

# Create a new group
$ sudo groupadd developers

# Change the group's GID (rarely needed)
$ sudo groupmod -g 1050 developers

# Remove a group
$ sudo groupdel developers

# List a user's group memberships
$ groups alice
alice : alice developers sudo

$ id alice
uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1002(developers)

Password policy

# Show a user's password-aging information
$ sudo chage -l alice
Last password change                                    : Oct 15, 2024
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 0
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7

# Force a password change every 90 days
$ sudo chage -M 90 alice

# Force a password change on next login
$ sudo chage -d 0 alice

4.9 Viewing identity

Several commands report information about the current user and their groups:

# Your username
$ whoami
alice

# Numeric UID
$ id -u
1001

# Full identity: UID, GID, supplementary groups
$ id
uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1002(developers)

# Effective identity (what the kernel checks for file access)
$ id -un
alice

# Who is currently logged in
$ who
alice    pts/0        2024-10-15 10:22

# A more detailed view of the same
$ w

The distinction between real and effective identity is important: for a setuid-root process, the real UID is the invoking user and the effective UID is root. File access is checked against the effective UID; accountability (for example, signalling) is checked against the real UID. This distinction is explored in detail in Unit 12.

4.10 Secure administration practices

The following practices are standard in any environment where security matters. They translate directly into the disciplines you will use in the laboratories of this course.

  1. Never log in as root directly. Log in as your ordinary account and use sudo when needed. Direct root login leaves no accountability trail and encourages careless commands.
  2. Use sudo for individual commands. Avoid sudo -i (an interactive root shell) unless you have a specific reason. Per-command elevation is safer and better logged.
  3. Create separate accounts for services. A web server should run as www-data (or an equivalent), not as root. Each service gets a UID with only the access it needs.
  4. Give each human user their own account. Never share accounts. Shared accounts destroy accountability (who did what?) and complicate access revocation (removing one person's access removes everyone's).
  5. Disable the shell for accounts that do not need it. Service accounts should have /usr/sbin/nologin as their shell, so even if a password is set they cannot be used to log in interactively.
  6. Remove accounts that are no longer needed. An account created for a temporary purpose and forgotten is an unmonitored entry point. Regular access reviews catch these.
  7. Restrict who is in the sudo group. Membership in sudo (or wheel on some distributions) is equivalent to full root access. Every member should be someone you would trust with the root password.
  8. Use PAM for password policy. Password complexity, length, and reuse rules are enforced by PAM modules, configured in /etc/pam.d/ and /etc/security/pwquality.conf. Do not rely on users to choose strong passwords.
  9. Enable auditing. The audit subsystem can log every command run under sudo, every change to /etc/passwd, and every failed login attempt. This is the evidence trail when something goes wrong.
  10. Review the account database periodically. Run cat /etc/passwd and cat /etc/group; check for accounts you do not recognise and group memberships that should have been removed.

4.11 What follows from this

The user and group model is the vocabulary of access control on Linux. Every file has an owner and a group; every process runs under a UID and a set of GIDs; every access decision compares the process's credentials to the resource's ownership. In the next lesson, we will see how this vocabulary translates into the concrete permission bits that appear in the output of ls -l, and how the kernel enforces those bits on every system call.

05 Worked example

To see the user and group model in action, trace what happens when a new developer account is created and added to a team group, then examine how the account interacts with a shared project directory.

Setting up a developer account with project access

  1. Create the group first.
    $ sudo groupadd -g 2000 projectx
    $ grep projectx /etc/group
    projectx:x:2000:
    The group exists but has no members yet.
  2. Create the user with a primary group and a home directory.
    $ sudo useradd -m -s /bin/bash -c "Dana Developer" dana
    $ grep dana /etc/passwd
    dana:x:1002:1002:Dana Developer:/home/dana:/bin/bash
    Note that useradd created a new group with the same name (dana, GID 1002) as the user's primary group — this is the default behaviour on most distributions.
  3. Add dana to the project group.
    $ sudo usermod -aG projectx dana
    $ groups dana
    dana : dana projectx
    Dana now has two groups: dana (primary) and projectx (supplementary).
  4. Create a shared project directory.
    $ sudo mkdir /srv/projectx
    $ sudo chgrp projectx /srv/projectx
    $ sudo chmod 2775 /srv/projectx
    $ ls -ld /srv/projectx
    drwxrwsr-x 2 root projectx 4096 Oct 15 11:00 /srv/projectx
    Three things are happening in that chmod:
    • 2 sets the setgid bit on the directory. New files created inside will inherit the directory's group (projectx) rather than the creating user's primary group.
    • 775 grants owner (root) and group (projectx) full read/write/execute, and others read/execute but not write.
  5. Verify with dana's account. If you can switch users (e.g., with su - dana as root), create a file in /srv/projectx:
    $ su - dana
    $ touch /srv/projectx/design.txt
    $ ls -l /srv/projectx/design.txt
    -rw-r--r-- 1 dana projectx 0 Oct 15 11:05 /srv/projectx/design.txt
    The file's owner is dana (the creating user), but its group is projectx (inherited from the directory via the setgid bit), not dana (the user's primary group). This is what makes the shared directory work: every file created by any project member is owned by the group.
  6. Confirm with another project member. Create a second user, add them to projectx, and verify that they can read and write files in /srv/projectx. Because they are members of projectx, the group permission bits apply to them.
  7. Check the effects of removal. If you remove dana from projectx:
    $ sudo gpasswd -d dana projectx
    $ groups dana
    dana : dana
    Dana loses access to the shared directory immediately — unless a file inside it was created with the wrong group, in which case that file's permissions may still permit her access. This is why the setgid bit on shared directories is important: it keeps files owned by the group so access control is consistent.

This pattern — a shared group plus a setgid directory — is the standard way to give a team access to a shared workspace on a Linux system. You will see it in production systems everywhere, and you will use it in the course's multi-user laboratory setups.

06 Interactive activity

Activity · explore users and groups on your VM

Open a terminal and run the following. Some commands require root access; use sudo where indicated. Record what you observe for each step.

  1. Identify yourself. Run id, whoami, and echo $USER. Do all three agree? Which is the canonical answer to "who am I on this system"?
  2. Inspect the account databases. Run head -5 /etc/passwd and head -5 /etc/group. Identify the UID and GID fields. What is the root account's UID?
  3. Count the accounts. Run wc -l /etc/passwd and wc -l /etc/group. How many accounts and groups does your VM have? How many are system accounts (UID < 1000) versus human accounts?
  4. List system accounts. Run awk -F: '$3 < 1000 {print $1}' /etc/passwd. Do you recognise any of them? What do they run?
  5. Examine group membership. Run groups to see your groups, and grep <yourname> /etc/group to see which group files mention you. Compare.
  6. Look at a setuid binary. Run ls -l /usr/bin/passwd /usr/bin/sudo /bin/su. Which have the setuid bit? What user owns each? Why does each of them need to be setuid?
  7. Read the shadow file (as root). Run sudo head -3 /etc/shadow. Note the hash format and the aging fields. Which account has a locked password?
  8. Create a test account. Create a user, add them to a group, and verify with id. Then clean up.
    $ sudo useradd -m testuser
    $ sudo groupadd testgroup
    $ sudo usermod -aG testgroup testuser
    $ id testuser
    $ sudo userdel -r testuser
    $ sudo groupdel testgroup

Reflect: which of these commands would you expect to see in a daily administration workflow? Which would be rare or dangerous?

07 Knowledge check

Check your understanding

Question 1

Why is a user's password hash stored in /etc/shadow rather than in /etc/passwd?

Show answer
Because /etc/passwd must be world-readable: many programs need to resolve usernames to UIDs and vice versa, so making the file accessible to every user is necessary. Before shadow passwords were introduced, the password hash was stored in that world-readable file, so any user could copy the hashes and run a password-cracking attack offline. Splitting the data into a world-readable /etc/passwd (without the hash) and a root-only /etc/shadow (with the hash) keeps the account information accessible while protecting the hashes.

Question 2

What is the difference between a user's primary group and their supplementary groups?

Show answer
The primary group is the group recorded in the GID field of /etc/passwd. Every user has exactly one primary group, and files the user creates are initially owned by this group (unless the parent directory has the setgid bit set, in which case the directory's group is used instead). The supplementary groups are additional groups the user belongs to, listed in the members field of /etc/group. A user can belong to any number of supplementary groups, and the kernel checks all of them when evaluating access to a file — a user has access if their primary group or any of their supplementary groups matches the file's group and the group permission bits allow the operation.

Question 3

Compare sudo, setuid, and Linux capabilities as mechanisms for granting elevated privileges.

Show answer
sudo grants temporary elevation on demand: an authorised user runs a specific command as root, authenticated with their own password. Policy is configured in /etc/sudoers, and every use is logged. Setuid is a file attribute that makes a binary run with the UID of its owner (usually root). It requires no administrator action at runtime, but every setuid binary is a privilege-escalation target and the binary receives the full set of root privileges. Capabilities disaggregate root into about 40 specific privileges, and a binary can hold only the capabilities it needs — for example, CAP_NET_BIND_SERVICE for binding to privileged ports. Capabilities implement least privilege most precisely, but the model is complex. Modern practice prefers capabilities where possible, sudo for administrative workflows, and setuid only as a last resort.

Question 4

What does the setgid bit on a directory do, and why is it important for shared project directories?

Show answer
On a directory, the setgid bit causes new files and subdirectories created inside to inherit the directory's group rather than the creating user's primary group. This is essential for shared directories because it keeps all files owned by the group, so every member of the group can access them via the group permission bits. Without setgid, a file created by user A would be owned by A's primary group and could be inaccessible to other project members even though they share the directory — because the file's group would not be the shared group.

Question 5

Why is it considered bad practice to use a shared account (for example, a "team" login that multiple people use)?

Show answer
Shared accounts destroy accountability and complicate access management. When something goes wrong — an accidental deletion, a security incident, a change to a production system — there is no way to attribute the action to a specific person, because everyone who uses the account appears as the same UID. Access cannot be revoked selectively: removing one person's access requires either changing the password for everyone (forcing everyone to relearn it) or disabling the account for all of them. A shared account also tends to accumulate permissions over time, since each user adds whatever they need. The correct practice is one account per person; shared access is achieved through group membership, not account sharing.

08 Unit discussion

Discussion prompt

The UNIX user model — one numeric UID per account, one primary group, a small set of supplementary groups — has survived for over fifty years. Modern systems layered on capabilities, ACLs, SELinux, and container namespaces, yet the core identity model is unchanged. Meanwhile, other operating systems and platforms have pursued different identity models: federated identity (OAuth, OIDC), per-request credentials in service meshes, and capability-based identity in WebAssembly.

Is the classical UID/GID model still the right foundation for a modern operating system, or is it being outgrown? Consider the needs of a multi-tenant cloud, a mobile device where every app runs under a distinct identity, and a microservices environment where thousands of services authenticate to each other continuously. Argue for whichever view you find more persuasive.

Post your response to the Unit 2 discussion forum and reply to at least two classmates. This activity supports CLO6 and CLO7.

09 Practice exercise

This ungraded exercise consolidates the lesson. Aim to spend about 45–60 minutes on it.

  1. Map your VM's accounts. List all accounts in /etc/passwd with a UID below 1000. For each, find one sentence online (or in the man pages) describing what service it is for. Which accounts have a real login shell? Which have nologin or false?
  2. Build a team workspace. Following the worked example, create two test users, a shared group, and a setgid directory. Verify that both users can create files in the directory and that each can read the other's files. Then remove one user from the group and confirm that they lose access to the directory.
  3. Audit setuid binaries. Run sudo find / -perm -4000 -type f 2>/dev/null to list every setuid binary on the system. For each, note what it does and why it needs elevated privileges. Which ones would you consider replacing with capabilities?
  4. Read a man page carefully. Read man 5 shadow. Pick two fields in the aging policy and describe what would change if you set them differently. Use chage to actually apply a policy to a test account and confirm it with chage -l.
  5. Write a script. Write a shell script that accepts a username as an argument and prints:
    • The user's UID and primary GID
    • The user's home directory and login shell
    • The user's supplementary groups
    • Whether the account is locked (has ! or * in the shadow password field)
    Handle the case where the user does not exist.
  6. Reflect. In your own words, describe the difference between a user's identity and their privileges. Give an example where a single user has different privileges in different contexts (for example, a normal login versus a sudo command).

10 Summary

  • A user account is a record that identifies a principal to the system. The kernel uses the numeric UID, not the username.
  • Account information is stored in /etc/passwd (world-readable) and /etc/shadow (root-only). Groups are in /etc/group and /etc/gshadow.
  • Every user has a primary group (in /etc/passwd) and can belong to any number of supplementary groups (in /etc/group). Access is checked against both.
  • Root (UID 0) bypasses ordinary permission checks and has full administrative privileges. Root is necessary but dangerous.
  • Privilege separation uses three mechanisms: sudo for temporary elevation on demand, setuid for binaries that run as their owner, and capabilities for granting only the specific privileges a program needs.
  • Account management tools include useradd, usermod, userdel, groupadd, groupmod, groupdel, and passwd. Always use usermod -aG to append to a group.
  • Secure administration practices: never log in as root directly, use sudo for individual commands, create separate accounts for services, use nologin shells, remove unused accounts, and review the account databases periodically.
  • Shared project directories use a group plus a setgid bit on the directory so that new files inherit the group and remain accessible to all members.

Looking ahead

Lesson 2.4 turns to permissions and access control — the concrete rules the kernel applies to every file access. The user and group model established here is the vocabulary that the permission system uses.

11 References

  • Stevens, W. R., & Rago, S. A. Advanced Programming in the UNIX Environment, 3rd ed., Section 1.7 and Section 4.4. Addison-Wesley, 2013.
  • Nemeth, E., Snyder, G., Whaley, B., & Mackin, D. UNIX and Linux System Administration Handbook, 5th ed., Chapters 6 and 8. Addison-Wesley, 2017.
  • Linux man pages: man 5 passwd, man 5 shadow, man 5 group, man 5 gshadow, man 8 useradd, man 8 usermod, man 8 groupadd, man 8 sudo, man 5 sudoers, man 8 chage, man 7 capabilities.
  • Shotts, W. The Linux Command Line, 5th ed., Chapter 9 (permissions). No Starch Press, 2019.
  • Linux kernel documentation: Documentation/admin-guide/ security/, in particular the capabilities documentation.
👤