1. The Inode and File Metadata
In Unix-like operating systems, a file's name is merely an entry in a directory table. The actual metadata—including ownership, size, timestamps, and permission bits—is stored inside an inode (index node).
The mode field in an inode is a 16-bit integer that stores:
- 4 bits: File type (regular file, directory, symbolic link, socket, FIFO, character/block device).
- 3 bits: Special permissions (SUID, SGID, Sticky Bit).
- 9 bits: Standard read/write/execute permissions across Owner, Group, and Others.
2. Anatomy of ls -l Output
When running ls -l in a terminal, the first column displays a 10-character string:
┬ └─┬─┘ └─┬─┘ └─┬─┘ │ │ │ │ │ │
1 2 3 4 5 6 7 8 9 10
- = regular file, d = directory, l = symlink.3. How the Linux Kernel Evaluates Access
A crucial and often misunderstood rule of Linux permissions is that evaluation stops at the first match:
- Owner Check: If the user attempting access is the owner of the file, only the owner bits (
u) are checked. If the owner does not have write permission, access is denied immediately—even if group or others have write permissions! - Group Check: If the user is not the owner, but belongs to the group that owns the file, only the group bits (
g) are evaluated. - Others Check: If the user is neither the owner nor in the group, the others bits (
o) apply. - Superuser Exception: The root user (
UID 0) bypasses normal read and write restrictions, though execute permission still requires at least one execute bit set on the file.
4. Understanding Umask (User Mask)
When a new file or folder is created, the system applies a umask to strip permissions from default maximum values:
To check your active shell umask, simply type umask into your terminal. A stricter umask of 027 creates directories with 750 and files with 640, preventing all public access by default.