Protection, Security and Virtualization
Read and set Unix permissions in octal, apply least privilege, and compare sandboxes, virtual machines and containers as ways to isolate software.
Welcome back!
Step 1 of 14Learn
Who may do what
A multi-user OS must answer one question millions of times a day: may this subject perform this operation on this object? The subject is usually a process acting for some user. The object is a file, directory, device, memory region or another process. The operation is read, write, execute, delete and so on.
Two concepts underpin the answer:
- Authentication: proving who you are, typically by logging in with a password, key or biometric. Every process then carries the identity, the user ID and group IDs, of whoever started it.
- Authorization: deciding what that identity may do, based on rules attached to objects.
In theory you could draw an access matrix with subjects as rows and objects as columns, each cell listing allowed operations. In practice it's stored in one of two ways. Access control lists (ACLs) attach to each object a list of who may do what with it. Windows NTFS uses detailed ACLs. Capabilities give each subject unforgeable tokens listing what it may access; file descriptors behave like capabilities once a file is open.
The guiding rule is the principle of least privilege: every program and user should have only the permissions it actually needs, and no more. A web server needs to read its web pages; it has no reason to modify system files or read users' email. If it is compromised, least privilege limits the damage.
Step 2 of 14Practice · Diagram
From login to "permission denied"
Which step is authorization?
Tap the shape that answers the question, then press Check.
- Authenticate
Password, key or biometric proves who you are.
- Process carries your UID
Every process you start inherits your user and group IDs.
- Request an operation
For example open a file for writing.
- Kernel checks permissions
Authorization: compares your IDs against the object's ACL or mode bits.
- Allow or deny
Step 3 of 14Learn
Unix permissions and octal notation
Classic Unix permissions are a compact ACL with three classes and three permissions.
The classes: the file's owner (user), its group, and others (everyone else). The permissions: r (read), w (write) and x (execute). For directories, the meanings shift: r lets you list the names, w lets you create, delete or rename entries, and x lets you enter the directory and access entries by name.
Running ls -l shows something like -rwxr-x---. Skip the first character (file type), then read three groups of three: owner rwx, group r-x, others ---.
Each group is often written as one octal digit, adding r = 4, w = 2, x = 1:
- rwx = 4 + 2 + 1 = 7
- r-x = 4 + 0 + 1 = 5
- r-- = 4
- --- = 0
So -rwxr-x--- is 750. Common values: 644 (rw-r--r--) for ordinary files that everyone may read but only the owner may change, 755 (rwxr-xr-x) for programs and directories, 600 (rw-------) for private files such as SSH keys. The command chmod 640 report.txt sets owner read-write, group read-only, others nothing.
The superuser, root (user ID 0), bypasses these checks. That's why administrators avoid working as root and use sudo for individual commands that genuinely need it.
Step 4 of 14Try the calculator
One permission digit
Enter 1 or 0 for each permission of one class (owner, group or others). Read = 4, write = 2, execute = 1.
- Octal digit
- 6
Step 5 of 14Practice · Work it out
Convert the permission string rw-r----- to its three-digit octal form.
Step 6 of 14Practice · Match the pairs
Match each octal mode to its permission string.
Tap an answer, then tap the place where it belongs (or drag it there).
- 755
- 644
- 600
- 711
Step 7 of 14Practice · What would you do?
What would you do?
A developer's web app can't read its configuration file, so they run chmod 777 on the app's whole folder and the error goes away. The file contains a database password. What's wrong with this fix, and what is better?
Step 8 of 14Learn
Sandboxing and the setuid problem
Sometimes a program must do something its user can't do directly. The passwd command lets you change your password, which means writing to a system file only root may modify. Unix solves this with the setuid bit: when set on a program file, the program runs with the file owner's privileges, root in this case, rather than the user's.
Setuid is powerful and dangerous. A bug in a setuid-root program, such as a buffer overflow, can give an attacker full control of the machine. Many famous privilege escalation attacks have exploited exactly that. Modern systems minimize setuid programs and split privileges more finely, for example with Linux capabilities, which grant individual powers such as binding to network ports below 1024 without granting full root.
A complementary idea is the sandbox: run a program with even fewer rights than its user has, so that if it's compromised it can do little harm. Examples:
- Mobile apps on Android and iOS each run in their own sandbox and must request permissions for the camera, contacts or location.
- Browsers run each site's code in sandboxed processes that can't open your files directly.
- Linux seccomp filters limit which system calls a process may make at all.
The pattern is consistent: assume any program might be compromised, and arrange the system so that a compromise stays contained.
Step 9 of 14Compare
Virtual machines vs. containers
| Aspect | Virtual machine | Container |
|---|---|---|
| What is virtualized | The whole hardware: CPU, memory, disks, network | The operating system's view: files, process IDs, network, users |
| Kernel | Each VM runs its own full OS kernel | All containers share the host's kernel |
| Managed by | A hypervisor such as KVM, Hyper-V, VMware ESXi or Xen | Kernel features (Linux namespaces and cgroups) driven by tools such as Docker or Kubernetes |
| Start time and overhead | Seconds to minutes; gigabytes of memory per VM | Often under a second; very little extra memory |
| Isolation strength | Strong: separate kernels | Weaker: a kernel bug can affect every container |
| Can run a different OS | Yes, for example Windows on a Linux host | No, Linux containers need a Linux kernel |
Step 10 of 14Learn
Hypervisors and containers in practice
A hypervisor creates virtual machines, each believing it has its own hardware. Type 1 (bare-metal) hypervisors such as VMware ESXi, Microsoft Hyper-V, Xen and Linux KVM run directly on the hardware and power most cloud servers. Type 2 (hosted) hypervisors such as VirtualBox and VMware Workstation run as applications on a normal OS, handy for testing another OS on your laptop.
Modern CPUs include hardware support for virtualization, Intel VT-x and AMD-V, which lets guest kernels run their own kernel-mode code at nearly full speed while the hypervisor stays in ultimate control. Nested page tables let the MMU translate guest addresses to real physical addresses in hardware.
Containers take a lighter approach. Linux namespaces give a group of processes its own view of process IDs, network interfaces, mount points and hostnames, so it looks like a separate machine. Control groups (cgroups) limit how much CPU, memory and I/O the group may use. A container image bundles an application with its libraries, so it runs the same on a developer's laptop and a production server.
The choice depends on the goal. Containers are ideal for packaging and densely running many trusted services. Virtual machines are preferred when you need a different OS or stronger isolation between untrusted tenants. Cloud providers often combine both: containers running inside lightweight VMs.
Step 11 of 14Practice · Select all that apply
Which statements about containers are correct? Select all that apply.
Select all that apply.
Step 12 of 14Note
Step 13 of 14Diagram
Isolation, from weakest to strongest
Tap a shape with to see more.
- Threads
Share everything in one process.
- Processes
Separate address spaces.
- Sandboxed process
Restricted system calls and permissions.
- Containers
Namespaces and limits, but a shared kernel.
- Virtual machines
Separate kernels under a hypervisor.
- Separate machines
Nothing shared at all.
Step 14 of 14Practice · Choose one
A hosting company wants to rent computing space to strangers who may run hostile code, and some customers need Windows while the hosts run Linux. Which approach fits best?
Lesson complete!