Linux Permission Model and rwx Bits
Linux permissions are not decoration on an ls listing.
They are inputs to an authorization decision made for a specific
process, identity, operation, and pathname. This lesson builds the
model needed to diagnose access failures without reflexively using
sudo.
Learning objectives
By the end of this lesson
- Identify the effective user and group credentials of a process.
- Decode symbolic and numeric permission modes.
- Explain read, write, and execute semantics for regular files and directories.
- Trace pathname access through every parent directory.
-
Build a permission evidence report using
id,stat,namei, and safe test operations.
1. Permission checks connect a process to an object
Linux evaluates access in context. A process has an effective user ID, an effective group ID, and supplementary groups. A filesystem object has an owner ID, a group ID, and mode bits. The requested operation—reading a file, creating an entry, traversing a directory, or executing a program—determines which permission is required.
flowchart TD P["Process credentials
effective UID and groups"] --> C{"Which class matches?"} O["Object owner, group,
and mode bits"] --> C C -->|UID equals owner| U["Use owner bits"] C -->|A group matches| G["Use group bits"] C -->|No identity match| R["Use other bits"] U --> Q{"Requested operation allowed?"} G --> Q R --> Q Q -->|yes| A["Access continues"] Q -->|no| D["EACCES / permission denied"]
The classes are alternatives, not additive fallbacks. If the process matches the file owner, Linux evaluates the owner bits; it does not then borrow a more permissive group or other bit. ACLs can extend this model and are covered in Lesson 5.
# Inspect the shell's identity and group set.
id
id -u
id -g
id -nG
# Inspect the current shell process and its effective credentials.
ps -o pid,ppid,euser,egroup,groups,comm -p "$$"
2. Read the mode string from left to right
A long listing such as -rwxr-x--- begins with a type
indicator and then three permission triplets: owner, group, and
other. The same mode can be written numerically. In each triplet,
read contributes 4, write contributes 2, and execute contributes 1:
\[m = 4r + 2w + x, \qquad r,w,x \in \{0,1\}\]
r4Read file content
w2Modify or truncate file content
x1Ask the kernel to execute the file
lab="$HOME/devops-academy/linux/chapter06/lesson01"
mkdir -p -- "$lab"
printf '#!/usr/bin/env bash
printf "permission lab\n"
' > "$lab/check.sh"
printf 'configuration=true
' > "$lab/app.conf"
ls -ld -- "$lab" "$lab/check.sh" "$lab/app.conf"
stat -c 'mode=%A octal=%a owner=%U group=%G name=%n' -- "$lab" "$lab/check.sh" "$lab/app.conf"
The execute bit does not guarantee that a file is a valid program. The file must also have a recognized executable format, such as an ELF binary or a script with a valid shebang.
3. Directory bits govern names, traversal, and entries
Directory permissions have different operational meanings because a directory maps names to inode references.
rList entry namesls directory cannot enumerate names
wCreate, remove, or rename directory entriesCannot add or delete names, even if file content is
writable
xTraverse/search and access known namesCannot reach objects below that directory
Removing a filename normally requires write and execute permission on its parent directory, not write permission on the file itself. Sticky directories add another restriction and are covered in Lesson 4.
# Display every pathname component and its mode.
namei -l -- "$HOME/devops-academy/linux/chapter06/lesson01/app.conf"
# Compare metadata for a file and its containing directory.
stat -c '%A %a %U:%G %n' -- "$HOME/devops-academy/linux/chapter06/lesson01" "$HOME/devops-academy/linux/chapter06/lesson01/app.conf"
4. Every parent directory participates
A readable file can still be inaccessible when one parent directory lacks execute permission for the relevant identity class. This is why checking only the final object often produces the wrong diagnosis. Start with the process identity, then inspect every component from the filesystem root to the target.
Read content, traverse a path, create a file, execute a program, or delete a name.
Record effective UID, primary group, supplementary groups, and whether a service changes identity.
Use namei -l and stat instead of
inspecting only the leaf.
Owner, a matching group, or other—not whichever triplet looks most permissive.
Use a non-destructive command under the same identity whenever possible.
5. Hands-on lab: build a permission evidence report
This lab creates a controlled tree, records modes and identity, and verifies read, execute, and directory-entry behavior without elevated privileges.
set -eu
lab="$HOME/devops-academy/linux/chapter06/lesson01"
rm -rf -- "$lab"
mkdir -p -- "$lab/bin" "$lab/config" "$lab/output"
printf '#!/usr/bin/env bash
printf "health=ok\n"
' > "$lab/bin/health-check"
printf 'port=8080
' > "$lab/config/app.conf"
chmod 750 -- "$lab/bin"
chmod 640 -- "$lab/config/app.conf"
chmod 755 -- "$lab/bin/health-check"
chmod 700 -- "$lab/output"
{
printf '=== identity ===
'
id
printf '
=== objects ===
'
find "$lab" -maxdepth 2 -printf '%M %m %u:%g %p
' | LC_ALL=C sort
printf '
=== path walk ===
'
namei -l -- "$lab/config/app.conf"
printf '
=== operation tests ===
'
test -r "$lab/config/app.conf" && printf 'config readable=yes
'
test -x "$lab/bin/health-check" && printf 'health executable=yes
'
test -w "$lab/output" && printf 'output directory writable=yes
'
} > "$lab/permission-report.txt"
cat -- "$lab/permission-report.txt"
"$lab/bin/health-check"
Verification checklist
6. Common permission-model mistakes
Checking only the final file
A parent directory may block traversal. Inspect the complete path.
Adding all three classes together
The kernel selects the applicable class; it does not accumulate owner, group, and other bits.
Equating file write with deletion
Deletion changes the parent directory entry. File content permissions answer a different question.
Using sudo as diagnosis
Root may bypass ordinary checks, hiding the identity or ownership error that will still break the service.
8. Knowledge check
Question 1. Which permission is required on each parent directory to reach a known pathname?
Question 2. If a process owns a file but the owner bits deny reading while the other bits allow it, can the process read the file through the other class?
Question 3. Why can a user sometimes delete a read-only file?
9. Summary
Linux discretionary permissions connect process credentials to object ownership and mode bits. The owner, group, or other class is selected for a specific operation; directory bits govern listing, entry changes, and traversal; and every parent directory participates in pathname access. Reliable diagnosis begins with identity and path evidence, not permission guessing.
10. Further reading
-
Linux man-pages:
credentials(7),inode(7),path_resolution(7), andaccess(2). -
GNU Coreutils manuals for
ls,stat, and mode representation. -
The
namei(1)manual for pathname-component inspection. - Filesystem Hierarchy Standard for conventional directory responsibilities.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0
Send only Ethereum/ERC-20 compatible assets to this
address.