Keys to the Kingdom: Users, Groups & Permissions
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.
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.
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(orIIS_IUSRS) service account—notroot. They can't read/etc/shadowor format your disks. - Human Error Protection: Standard users cannot accidentally delete
/etcorC:\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 withsudo. Linux checks/etc/sudoers, asks for your password, logs the exact command to/var/log/auth.log, runs that one command asroot, and drops you back to normal privileges. - Windows UAC (User Account Control): Even if your account is in the
Administratorsgroup, 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.
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:
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 toaliceand the group towebadmins.
✏️ 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.
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) ANDContractors(Explicit Deny Write), can she edit the file? No—Explicit Deny always wins. - What do
(OI)and(CI)mean inicacls? 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!