Lecture 3
01 / 00

Page ↑ / Page ↓ to move · scroll works too

Linux & DevOps — Lecture 3 of 8

Whose System Is This?

You can move around and reach the machine.
Today: how it’s organized, how software gets on it,
and who’s allowed to touch what.

All slides available at
slides.raafat.io

The shell was the tool — this is the machine it operates on

Lecture 2 gave you the hands. This lecture gives you the map: where files are supposed to live, how packages arrive and get tracked, and the permission model that decides whether a command you just typed is even allowed to run. Every “permission denied” for the rest of this course traces back to something in today’s lecture.

dnf rpm passwd chmod chown setfacl sudo
01

The Filesystem Hierarchy

  • Everything is a file, from one root
  • The Filesystem Hierarchy Standard
  • The directories you'll actually use
  • Mounts and disk basics

One tree, no drive letters

Linux has a single root, /. There’s no C:\ — a second disk, a USB stick, or a remote share all get grafted onto the same tree at some directory, via mounting. Ask “what filesystem is this path on” with df, not by looking at the path itself.

~
$ df -hT /
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs 18G 3.1G 15G 18% /

The Filesystem Hierarchy Standard (FHS)

  • /etc — system-wide configuration, almost always plain text
  • /var — data that changes at runtime: logs, spool queues, caches
  • /home — personal directories, one per user
  • /opt — self-contained third-party software, one directory per app
  • /usr — the OS itself: binaries, libraries, shared data
  • /tmp — temporary files, cleared on a schedule or at reboot
  • /proc and /sys — not real files, a live window into the kernel

The FHS is a convention, not a law enforced by the kernel — but every RPM package, every systemd unit, and every other admin on the planet assumes you’re following it. Put your own app under /opt, not scattered across the tree.

Locating things you didn’t put there

~
$ which sshd
$ whereis sshd
$ file /etc/passwd
$ readlink -f /etc/localtime
$ stat /etc/shadow
which finds it on $PATH, whereis also finds the man page and source. file tells you what a file actually is, not what its extension claims. stat shows size, timestamps, permissions, and ownership in one shot.

Mounting: attaching a filesystem to a directory

~
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
└─rhel-root 253:0 0 18G 0 lvm /
$ mount /dev/sdb1 /mnt/data
$ umount /mnt/data
$ cat /etc/fstab

A manual mount doesn’t survive reboot — a line in /etc/fstab is what makes it permanent. This isn’t a full storage lecture; you need just enough to answer “what’s mounted where” when something runs out of space.

02

Package Management

  • Why packages instead of tarballs
  • dnf: install, remove, search, update
  • Repositories and where packages come from
  • rpm: inspecting what's already installed
  • subscription-manager, briefly

A package is software plus a promise

A .rpm isn’t just files to copy — it declares what it depends on, where each file goes, and how to cleanly remove itself later. The package manager tracks all of that in a database, so “what’s installed” and “can I safely remove this” are answerable questions instead of guesses.

Repository remote package index
→
dnf resolves dependencies
→
rpm database local install records

dnf: the day-to-day tool

~
$ sudo dnf install httpd
$ sudo dnf remove httpd
$ sudo dnf update
$ dnf search "text editor"
$ dnf list installed
$ dnf info nginx
$ dnf history
dnf resolves and installs dependencies automatically, and dnf history gives you an undo log — dnf history undo <id> reverses a specific transaction if an update goes wrong.

Where packages actually come from

~
$ dnf repolist
$ cat /etc/yum.repos.d/rhel.repo
$ sudo dnf config-manager --add-repo https://example.com/repo
$ sudo dnf install epel-release

Each file in /etc/yum.repos.d/ points at a repository URL. RHEL’s own repos require an active subscription; EPEL (“Extra Packages for Enterprise Linux”) is the most common add-on repo for software Red Hat doesn’t ship directly.

rpm — the low-level tool

~
$ rpm -qa | grep openssh
$ rpm -qi openssh-server
$ rpm -ql openssh-server
$ rpm -qf /usr/sbin/sshd

subscription-manager

~
$ sudo subscription-manager \
register
$ subscription-manager status
$ subscription-manager \
list --available
dnf calls rpm under the hood — reach for rpm directly when you already know the package name and just want facts about it, no network required. subscription-manager is what grants access to RHEL's own repositories in the first place.
03

Users & Groups

  • Why Linux is multi-user by design
  • /etc/passwd, /etc/shadow, /etc/group
  • Creating and managing accounts
  • Primary vs. supplementary groups

Every process runs as somebody

There’s no process without an owner. That owner — a UID, resolved to a username — is what permission checks are made against. root is UID 0 and bypasses most of those checks entirely, which is exactly why you don’t operate as root by default.

~
$ id
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
$ whoami
$ ps -eo pid,user,cmd | head

Three files, one identity model

/etc/passwd
student:x:1000:1000:Student User:/home/student:/bin/bash
/etc/shadow
student:$6$abc123...:19800:0:99999:7:::
/etc/group
wheel:x:10:student,ops
/etc/passwd is world-readable and holds identity, not secrets — the x means the real password hash lives in /etc/shadow, readable only by root. /etc/group maps group names to members.

Creating and changing accounts

~
$ sudo useradd -m -s /bin/bash -c "Ops User" ops
$ sudo passwd ops
$ sudo usermod -aG wheel ops
$ sudo userdel -r ops
$ sudo groupadd deploy
-m creates the home directory, -aG appends to supplementary groups — leaving off -a replaces the user's whole group list, a classic way to accidentally lock someone out of their own groups.

Primary group vs. supplementary groups

Primary

  • One per user, set in /etc/passwd
  • Owns every file the user creates
  • Changed with usermod -g

Supplementary

  • Zero or more, listed in /etc/group
  • Grants access without changing file ownership
  • Changed with usermod -aG
wheel is the supplementary group that traditionally grants sudo access on RHEL-family systems — membership in it is a permission grant, not a change of identity.
04

Standard Permissions

  • Reading rwx and the three scopes
  • chmod: symbolic and numeric
  • chown and chgrp
  • umask: the default you never typed

Ten characters, three audiences

~
$ ls -l /etc/shadow /usr/bin/passwd
-rw-r-----. 1 root root 1214 Sep 2 09:14 /etc/shadow
-rwsr-xr-x. 1 root root 36000 Aug 14 03:22 /usr/bin/passwd

Position one is file type; the next nine split into three groups of rwx — owner, group, everyone else. On passwd, the s in place of owner-execute is the setuid bit: it runs as root no matter who invokes it, which is exactly how an unprivileged user is allowed to change their own password.

chmod: symbolic and numeric

~
$ chmod u+x deploy.sh
$ chmod g-w shared.conf
$ chmod 644 app.conf
$ chmod 755 deploy.sh
$ chmod -R 750 /opt/app
  • Numeric: 4 read, 2 write, 1 execute, summed per scope — 7=rwx, 5=r-x
  • 644 is the standard file default, 755 the standard executable/directory default

chown & chgrp: who owns it

~
$ sudo chown deploy app.log
$ sudo chown deploy:deploy /opt/app
$ sudo chown -R deploy:deploy /opt/app
$ sudo chgrp ops shared.conf

Only root can hand a file to a different owner; any owner can change the file’s group, as long as they belong to the target group themselves.

umask: the permission bits you never typed

~
$ umask
0022
$ touch newfile.txt && ls -l newfile.txt
-rw-r--r--. 1 student student 0 Sep 12 10:03 newfile.txt
$ umask 0027

New files start from 666, new directories from 777, and umask subtracts bits from that default — 022 is why a freshly created file lands at 644 instead of 666. Set it in a shell startup file to change the default for every new file a user creates.

05

ACLs & sudo

When owner/group/other isn't granular enough, and when root shouldn't mean everyone.

  • The limits of rwx
  • setfacl and getfacl
  • sudo and /etc/sudoers
  • Least privilege in practice

rwx only has three seats at the table

Standard permissions can grant exactly one owner and one group. The moment you need “these three specific people, plus the group, each with different access” — a shared team directory being the classic case — chmod alone can’t express it. That’s what ACLs (Access Control Lists) are for.

setfacl & getfacl

~
$ sudo setfacl -m u:ops:rwx /srv/team
$ sudo setfacl -m g:auditors:r-x /srv/team
$ getfacl /srv/team
$ setfacl -d -m u:ops:rwx /srv/team
$ setfacl -x u:ops /srv/team
-m modifies an entry, -d sets a default ACL a directory applies to everything created inside it afterward, -x removes an entry. A + after the mode in ls -l output (rwxr-x---+) is the tell that a file has ACL entries beyond the basic three.

sudo: borrowed privilege, on the record

~
$ sudo systemctl restart nginx
$ sudo -l
$ sudo -u deploy whoami
$ sudo visudo

Every sudo invocation is logged to /var/log/secure — who ran what, as whom, and when. Always edit sudo rules with visudo, never a text editor directly: it validates syntax before saving, so a typo can’t lock every admin out of sudo at once.

/etc/sudoers: precise grants, not all-or-nothing

/etc/sudoers.d/ops
%wheel ALL=(ALL) ALL
ops ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart app
deploy ALL=(ALL) /usr/bin/podman *
  • Group rules use %groupname; user rules use the bare username
  • Restricting the command list is what "least privilege" looks like in practice
  • Drop custom rules in /etc/sudoers.d/ instead of editing the main file — easier to review and to revert
06

Lab & Logistics

  • Create users/groups and a permission scenario
  • Set up a shared team directory with ACLs
  • Where to find these slides again

Fin

All slides available at
slides.raafat.io