Chapter 3: Access Control

Bash for Cybersecurity

Learning objectives

  1. Explain how users, groups, and privileges identify access rights, and create and test a regular and an administrative account on a Linux VM.
  2. Read and change symbolic and octal file permissions.
  3. Predict new-file and new-directory modes using umask, including its limits.
  4. Explain setuid, setgid, and sticky-bit observations without changing system executables.
  5. Audit a student-owned fixture tree and justify targeted permission corrections.

Chapter flow

  1. Users, Groups & Privileges
  2. Permissions and Ownership
  3. Defaults and Special Bits

Identify the requesting process

whoami
id
id -u
id -g
id -G

Match effective identity and groups to the target's owner/group.
Account ranges and name services vary; do not infer privilege from a UID threshold.

Choose the applicable class

- rw- r-- ---
|  |   |   |
type owner group others

Traditional mode checks select owner, group, or others; they do not add all three grants.
ACLs and other policy can add rules. Root has extensive power, not unlimited authorization.

Create a regular and an admin account

On your own VM, in an SSH session:

sudo adduser student_user
sudo adduser student_admin
sudo usermod -aG sudo student_admin
getent group sudo
id student_admin

Daily work as student_user; student_admin only when a task needs root.

Keep the -a; test by logging in

$ sudo usermod -G lab_web student_admin
$ id -nG student_admin
student_admin lab_web

-G alone replaces every supplementary group: sudo is gone.
Test each account: su - student_admin then sudo -v; student_user should be refused.

File bytes and directory entries differ

Bit Regular file Directory
r Read content. Enumerate names.
w Modify content. Manage entries, normally with search.
x Request direct execution. Search/traverse to a child.

Removing a file's name depends on its parent, including sticky rules.
A readable file can be inaccessible through an unsearchable directory.

Apply an intended policy

chmod 0750 reports
chmod 0640 reports/summary.txt
chmod o-rwx reports reports/summary.txt
ls -ld reports reports/summary.txt

The directory needs search; report text does not need execute.
Avoid one recursive numeric mode for a mixed file/directory tree.

Ownership is a separate decision

Patterns, not commands to run against another account:

chown owner[:group] path
chgrp group path

Changing the owner normally requires privilege on Linux.
Changing the group does not itself grant group read or write.
Use only your owned fixtures; account and sudo-policy edits are separate work.

umask clears requested bits

Without a default ACL: requested mode with mask bits cleared.
This is a bit operation, not ordinary subtraction.

Mask File requested as 0666 Directory requested as 0777
0022 0644 0755
0077 0600 0700
0007 0660 0770
0003 0664 0774

Test new names in a subshell

(
    umask 0007
    touch scratch/team_report.txt
    mkdir scratch/team_directory
)
ls -ld scratch/team_report.txt scratch/team_directory

An existing file's mode is not recalculated by touch.
Inherited ACLs and a program's requested mode can change the result.

Recognize special bits

Bit Contribution Meaning to investigate
setuid 4000 Effective user identity on eligible execution.
setgid 2000 Eligible execution identity or directory group inheritance.
sticky 1000 Restrictions on entry removal/rename in a directory.

Lowercase s/t includes the execute bit; uppercase S/T does not.
Do not set special bits on system executables or test another account without a separate lab.

Audit a bounded fixture

find scratch -type f -perm -0002 -print
find scratch -type d -perm -2000 -print
find scratch -type d -perm -1000 -print

Record path, ownership, mode, intended policy, interpretation, and verification.
A mode-bit match is not an effective-access verdict.
A private parent can restrict access despite broad bits on its children.

Sources and verification boundaries

Linuxize: id,
chmod,
chown,
chgrp,
and umask.

Linux manual pages and installed macOS manuals support platform notes.
Single-account fixtures do not test cross-account sticky-bit denial or privileged execution.

Least privilege applied to people. These commands persist, so they run on the student's VM, not the book runner. Ask: why verify with getent instead of trusting adduser's messages?

Repair: sudo usermod -aG sudo,users student_admin from another sudo account. The refusal for student_user is the evidence we wanted.