Linux Intermediate 01 — Users, Groups, sudo, and Special Permissions

Linux course index · Linux Intermediate category · Lesson 1 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Inspect identity records, understand sudo, and build a group-inheriting directory in a disposable VM.

Concepts and setup

UIDs and GIDs identify users and groups. Primary and supplementary groups can both matter. Query through getent instead of assuming every account lives in /etc/passwd. Never display or copy /etc/shadow into a report. Use sudo for a scoped task instead of working in a root shell. Administrative group policy differs by distribution, commonly sudo on Ubuntu and wheel on Red Hat-family systems. Verify the real sudo policy with sudo -l.

SUID on eligible executables can change the effective UID. Inspect it read-only on system programs. SGID on a directory makes new entries inherit the directory’s group. The sticky bit limits who can delete or rename entries in a shared writable directory.

Inspect the current identity and special bits without changing privileges

id
getent passwd "$(id -un)" | cut -d: -f1,3,4,6,7
stat -c '%a %A %n' /tmp
stat -c '%a %A %n' "$(command -v passwd)"

Possible output

uid=1000(learner) gid=1000(learner) groups=1000(learner),27(sudo)
learner:1000:1000:/home/learner:/bin/bash
1777 drwxrwxrwt /tmp
4755 -rwsr-xr-x /usr/bin/passwd

This illustrates common layouts. Do not change /tmp or the passwd binary. Lowercase s or t means the corresponding execute bit is also set.

Verify SGID group inheritance on a directory you own

lab=$(mktemp -d)
mkdir "$lab/shared"
chgrp "$(id -gn)" "$lab/shared"
chmod 2770 "$lab/shared"
touch "$lab/shared/report.txt"
stat -c '%a %A %G %n' "$lab/shared" "$lab/shared/report.txt"

Possible output

2770 drwxrws--- learner /tmp/tmp.ABC/shared
644 -rw-r--r-- learner /tmp/tmp.ABC/shared/report.txt

Actual paths, modes, and groups vary. SGID controls group inheritance, not guaranteed group write access. A directory inside this private temporary parent is not reachable by other users. Use an explicit ACL or a suitable group-owned parent in a shared lab.

Questions only

Quick-check questions

  1. What does getent do that reading a single local file might not?
  2. Does SGID on a directory make every new file writable by the group?

Assessment questions

  1. Why is -a important if a lab admin runs usermod -aG project labuser?
  2. What special bit often appears on /tmp, and what does it restrict?
  3. How would you verify the identity and policies of a newly authorized lab admin without exposing password data?

Questions and answers

Quick-check answers

  1. What does getent do that reading a single local file might not?
    Answer — It consults the configured name service, which may include nonlocal account records.
  2. Does SGID on a directory make every new file writable by the group?
    Answer — No. Group ownership inheritance and file write permission are separate.

Assessment answer key

  1. Why is -a important if a lab admin runs usermod -aG project labuser?
    Answer — It appends to supplementary groups rather than replacing the existing list. Existing sessions may need a fresh login.
  2. What special bit often appears on /tmp, and what does it restrict?
    Answer — The sticky bit limits deletion or renaming to authorized cases such as the entry owner, directory owner, or a privileged process.
  3. How would you verify the identity and policies of a newly authorized lab admin without exposing password data?
    Answer — Start a fresh session as the lab user. Use id and sudo -l to confirm groups and authorized commands.

Source articles on this site

Continue the course

Next lesson 02 — Access Control Lists and Shared Directories.

Linux course index · Linux Intermediate category · Lesson 1 of 9

Leave a Reply