📘 Visual Posts About Contact
Explore 📋 Cheat Sheets ✏️ Practice 🎮 Games 🎬 Simulations 🃏 Flashcards 🎯 Interactive Layers 📖 Storytelling
💜 Support my site

Keys to the Kingdom: Users, Groups & Permissions

Module 06 Zero to Hero Linux & Windows

Every server has doors, files, and vaults. Who gets which keycard—and what happens when someone gets hacked? Learn the Principle of Least Privilege, why you never live as root, how Linux chmod 750 math works, and how Windows NTFS ACLs protect your data.

Start Learning ↓
HOTEL KEYCARD ACCESS CONTROL Guest Keycard Standard User Room 204 Only App & Home Folder /home/alice | C:\Users\alice ALLOWED (Limited) Staff Keycard Group / sudo Floor 2 + Supply Web Root & Logs /var/www | C:\inetpub ELEVATED ON DEMAND Master Keycard root / SYSTEM Locked in Safe! OS Core & Kernel /etc/shadow | C:\Windows TOTAL POWER (HIGH RISK)

01 Principle of Least Privilege

Define: The Principle of Least Privilege (PoLP) means giving every human user, background service, and application only the exact permissions required to complete its job—and nothing more.

🏨 Real-World Analogy: The Hotel Keycard System

Imagine checking into a hotel. The front desk gives you a Guest Keycard that opens the front lobby, the elevator, and Room 204. Housekeeping gets a staff keycard that opens rooms on Floor 2 and the linen closet, but not the hotel's bank safe. Only the General Manager has the Master Key—and even the GM keeps it locked in a safe instead of carrying it to breakfast. Why? Because if a guest loses their keycard in a taxi, the thief only gets into Room 204—not the entire hotel!

Understand: Users vs. Groups (Why We Never Permission Individuals)

On a real server, you don't hand out permissions to individual people one by one. Imagine a company with 50 developers and 200 folders. If a developer quits or switches teams, editing 200 folders by hand is a nightmare. Instead, you put Users into Groups (roles), and assign permissions to the Groups.

ROLE-BASED ACCESS: USERS → GROUPS → RESOURCES 1. USERS (Identities) alice UID: 1001 bob UID: 1002 charlie UID: 1003 (Intern) 2. GROUPS (Roles) webadmins GID: 2001 Members: alice, bob guests Members: charlie DENIED 3. RESOURCES /var/www/app Group: webadmins Read + Write /public/docs Read-Only Access

Know & When: Blast Radius Containment

  • Web Server Compromise: If a hacker exploits a bug in Nginx or Apache, they inherit the permissions of the www-data (or IIS_IUSRS) service account—not root. They can't read /etc/shadow or format your disks.
  • Human Error Protection: Standard users cannot accidentally delete /etc or C:\Windows\System32.
  • When to Apply: Always! Every new user, database, script, or API key starts with zero permissions and only receives what it strictly needs.

🧠 Memory Trick: P.O.L.P.

Please Only Leave Permitted — If a user or service doesn't need a key to that door today, take the key away.

Checkpoint: Can You Explain This?

  • Why do we assign folder permissions to Groups instead of individual Users?
  • What is "blast radius" and how does Least Privilege shrink it?

02 Root, sudo & Windows UAC

Define: On Linux, root (UID 0) is the all-powerful superuser with zero restrictions. On Windows, the built-in Administrator (and NT AUTHORITY\SYSTEM) holds equivalent power. Logging in directly as these accounts for everyday work is one of the fastest ways to destroy a server.

🚨 Why You NEVER Log In as root Daily

When you are logged in as root, the operating system never asks "Are you sure?" One stray space in a command like rm -rf / tmp/logs (notice the space after /!) will wipe your entire server in seconds. Worse, every browser tab, script, or SSH session you run as root gives attackers instant god-mode if compromised.

Understand: sudo (Linux) vs. UAC Split Tokens (Windows)

Instead of living as the superuser, modern servers use just-in-time elevation:

  • Linux sudo ("Superuser Do"): You log in as a normal user (e.g., deploy). When you need to install a package or restart Nginx, you prefix the command with sudo. Linux checks /etc/sudoers, asks for your password, logs the exact command to /var/log/auth.log, runs that one command as root, and drops you back to normal privileges.
  • Windows UAC (User Account Control): Even if your account is in the Administrators group, Windows hands you a Filtered Standard Token at login. Your browser, email, and apps run as a standard user. Only when you right-click "Run as Administrator" and approve the UAC prompt does Windows unlock your Elevated Admin Token for that specific app.
LINUX: sudo WORKFLOW 1. Normal User (deploy) $ sudo apt update 2. /etc/sudoers Gatekeeper Checks permission + logs to auth.log 3. Runs 1 Command as root Then returns to standard user WINDOWS: UAC SPLIT TOKEN 1. Login: Filtered Standard Token Browser & apps run unprivileged 2. UAC Consent Prompt "Allow this app to make changes?" 3. Elevated Admin Token Granted only to that specific process

Execute: Safe sudo Rules

Never edit /etc/sudoers directly with a plain editor—a single syntax typo can lock everyone out of sudo! Always use sudo visudo, which validates your syntax before saving.

🧠 Memory Trick: visudo = "Verify In sudo"

Think of visudo as a spell-checker for server keys. Also remember: su - switches you permanently into another user, while sudo borrows power for one task only.

✏️ Practice Problem 1: Choosing the Right Elevation

You manage a production Ubuntu server with three junior admins: Maya, Liam, and Noah. You want to know who restarted the database at 2:00 AM if something breaks. Should you share the root password with all three, or give each person their own account in the sudo group? Why?

Show Solution

Give each admin their own user account in the sudo group. Sharing the root password destroys accountability—logs will only show root. With individual sudo accounts, /var/log/auth.log (or journalctl) records the exact username, timestamp, and command executed, and you can revoke Maya's or Liam's access in one command without changing anyone else's password.

03 Linux Permissions Visually

Define: Every file and directory in Linux has three permission buckets—Owner (User, u), Group (g), and Others (o)—and three permission bits: Read (r = 4), Write (w = 2), and Execute (x = 1).

When you run ls -la, Linux prints a 10-character code at the start of every line, like -rwxr-x---. Let's decode every single character visually:

DECODING -rwxr-x--- (chmod 750) - r w x r - x - - - TYPE - = File d = Dir OWNER (u) r(4) + w(2) + x(1) = 7 Full Control GROUP (g) r(4) + -(0) + x(1) = 5 Read & Run Only OTHERS (o) -(0) + -(0) + -(0) = 0 No Access COMMAND: chmod 750 deploy.sh  |  chown alice:webadmins deploy.sh Read = 4  •  Write = 2  •  Execute = 1  •  Dash (-) = 0

Know: Files vs. Directories (The #1 Beginner Trap)

Bit (Value) Meaning on a File Meaning on a Directory (Folder)
r (4) View or copy the file's contents (cat). List the filenames inside the folder (ls).
w (2) Edit or overwrite the file's contents. Create, rename, or delete files inside the folder.
x (1) Run the file as a program or script. Enter (cd into) the folder and access files inside.

🧠 Memory Trick: 4 Eyes, 2 Hands, 1 Foot

4 to Read (like four eyes with glasses), 2 to Write (two hands on a keyboard), and 1 to eXecute (one foot to step inside a directory or kick off a script)!

Execute: Common Permission Patterns

  • chmod 750 script.sh — Owner can edit & run (7), Group can read & run (5), Others get nothing (0).
  • chmod 644 index.html — Owner can edit (6), Group & Others can only read (4). Ideal for public web files.
  • chmod 600 ~/.ssh/id_ed25519 — Only the owner can read/write (6). SSH refuses to work if private keys are readable by others!
  • chown alice:webadmins /var/www/app — Changes the file owner to alice and the group to webadmins.

✏️ Practice Problem 2: Decode the Octal

You run chmod 640 secrets.env and chmod 755 /var/www/html. Translate both into rwx strings (e.g., rw-r-----) and explain who can do what.

Show Solution

1. 640 → -rw-r-----: Owner (6 = 4+2) can Read & Write. Group (4) can Read only. Others (0) have no access.

2. 755 → drwxr-xr-x: Owner (7 = 4+2+1) can list, create/delete, and cd into the folder. Group (5 = 4+1) and Others (5 = 4+1) can list and cd into the folder, but cannot modify or delete files.

04 Windows NTFS Permissions & Inheritance

Define: Unlike Linux's three fixed buckets (Owner/Group/Others), Windows NTFS uses ACLs (Access Control Lists). Think of an ACL as a VIP guest list attached to every file and folder, containing individual rules called ACEs (Access Control Entries) for as many specific users or groups as you want.

Understand: Inheritance & The Golden Rule of NTFS

By default, folders pass their permissions down to all subfolders and files inside them—this is called Inheritance. When Windows checks whether a user can open a file, it evaluates rules in a strict priority order. The #1 rule to memorize is: Explicit Deny ALWAYS overrides Allow.

WINDOWS NTFS PERMISSION PRECEDENCE (TOP WINS) 1. EXPLICIT DENY Always wins! Blocks access immediately, even if Allow exists. 2. EXPLICIT ALLOW Set directly on this file/folder. Overrides inherited rules. 3. INHERITED DENY Passed down from parent folder. Beats inherited Allow. 4. INHERITED ALLOW Default permissions flowing down from parent folder. No matching Allow rule at all? → IMPLICIT DENY (Access Blocked)

Execute: Managing Windows ACLs with icacls

On Windows Server Core or in PowerShell automation scripts, administrators inspect and modify NTFS permissions using icacls:

# 1. View current NTFS permissions on a web folder
icacls C:\WebApp

# 2. Grant "WebAdmins" Modify (M) access, inherited by subfolders (CI) & files (OI)
icacls C:\WebApp /grant "WebAdmins:(OI)(CI)M"

# 3. Disable inheritance and convert inherited rules into explicit rules (for a private folder)
icacls C:\WebApp\Secrets /inheritance:d

Checkpoint: NTFS Mastery

  • If Alice is in WebAdmins (Allow Modify) AND Contractors (Explicit Deny Write), can she edit the file? No—Explicit Deny always wins.
  • What do (OI) and (CI) mean in icacls? Object Inherit (files) and Container Inherit (subfolders).

05 Practical Lab: Create a Non-Root Admin & Lock Down /var/www

Let's put everything together. In this lab, you will create a dedicated non-root admin account (deploy), create a webteam group, and lock down a web application folder so unauthorized users cannot read your database passwords.

⚠️ Never Run chmod -R 777!

Tutorials on random forums often tell you to "fix" permission errors with chmod -R 777 /var/www. That gives every user and compromised process on the server full Read, Write, and Execute power—like propping the hotel front door open with a brick. Always use 750/755 for folders and 640/644 for files.

Linux Lab (Ubuntu / Debian / RHEL)

# 1. Create a non-root user named "deploy" and add to sudo group
sudo adduser deploy
sudo usermod -aG sudo deploy      # (Use "wheel" instead of "sudo" on RHEL/Rocky)

# 2. Create a shared group for your web team and add deploy
sudo groupadd webteam
sudo usermod -aG webteam deploy

# 3. Create the app directory and a secret config file
sudo mkdir -p /var/www/myapp
sudo touch /var/www/myapp/config.env

# 4. Set ownership to deploy:webteam and lock down permissions
sudo chown -R deploy:webteam /var/www/myapp
sudo chmod 750 /var/www/myapp
sudo chmod 640 /var/www/myapp/config.env

# 5. Verify your work!
id deploy
ls -ld /var/www/myapp
ls -l /var/www/myapp/config.env

Windows Server Equivalent (PowerShell)

# 1. Create a local user and group, then add the user to the group
New-LocalUser -Name "deploy" -NoPassword
New-LocalGroup -Name "WebTeam"
Add-LocalGroupMember -Group "WebTeam" -Member "deploy"

# 2. Create folder, disable inheritance, and grant WebTeam Modify rights
New-Item -Path "C:\WebApp" -ItemType Directory
icacls C:\WebApp /inheritance:r
icacls C:\WebApp /grant "Administrators:(OI)(CI)F" "WebTeam:(OI)(CI)M"

✅ Expected Output Check

ls -ld /var/www/myapp should show drwxr-x--- ... deploy webteam, and config.env should show -rw-r----- ... deploy webteam. Anyone outside webteam gets Permission denied!

🎯 Knowledge Check

Test your Module 06 mastery (instant feedback): Score: 0 / 4

1. According to the Principle of Least Privilege, why should you avoid logging in as root for daily server administration?

Because root cannot install software packages❌
To limit the blast radius of mistakes or hacks and maintain an audit trail via sudo✅
Because Linux automatically deletes the root account after installation❌

2. What permissions does chmod 750 deploy.sh grant to the Owner, Group, and Others?

Owner: Read/Write/Execute, Group: Read/Execute, Others: No access✅
Owner: Read only, Group: Write/Execute, Others: Read only❌
Everyone on the server gets full Read/Write/Execute access❌

3. On Linux, what does the Execute (x) permission allow you to do on a directory?

List the filenames inside the directory with ls❌
Delete all files inside the directory❌
Enter (cd into) the directory and traverse into its files✅

4. On a Windows NTFS folder, Bob belongs to Sales (Explicit Allow: Read) and TempStaff (Explicit Deny: Read). What happens when Bob tries to open the folder?

Bob can read the folder because Explicit Allow wins❌
Access is denied because Explicit Deny always overrides Allow✅
Windows asks Bob to approve a UAC prompt to read the folder❌