$_ CLI In Depth
Learning progress 0%
case permissions users sudo

System Deep-Dive: How the Kernel Checks Permissions

5 min read Module 5: Users, Permissions & sudo Updated Dec 5, 2026
Cheat Sheet
0:00 / 3:14

The question the kernel answers

When a process calls open on a path, the kernel must answer one question: may this process perform this access on this object? The answer depends on the identity of the process, the owner and group and mode of every object on the path, and a few special rules. The kernel does not ask the program whether it is allowed. It makes the check itself, on every call, so a program cannot skip it.

The check is called discretionary access control, because the owner of an object decides, through its mode, who may access it. The rest of this unit describes the classic algorithm. Modern systems can add stricter layers on top, but the classic algorithm is the one that explains the everyday errors you will see.

Step one: walk the path

A path such as /workspace/project/src/main.c is resolved one component at a time. The kernel starts at the root directory, looks up workspace, and then needs search permission on the directory it is in before it can look up the next name. It repeats this for each step. Any directory on the path that blocks search stops the whole walk, even when the final file is perfectly readable.

BASH1 lines
stat -c "%A %a %n" / /workspace /tmp

The output shows the mode of each directory on a short path. Each of them must carry execute for you, or for a class that includes you, before a deeper name can be reached. The check is made directory by directory, so a single mode of 700 owned by another account can make the entire subtree unreachable to you.

Step two: choose one class

Once the kernel has reached the final object, it compares the process identity with the object owner. If the effective UID equals the owner UID, the kernel uses the owner triplet and stops. If the UID does not match, the kernel checks whether the effective GID or any supplementary group equals the file group. If one matches, it uses the group triplet and stops. Only if neither matches does it use the other triplet.

The algorithm stops at the first match. That is why owner bits can deny an access that the group bits would allow. If you are the owner and the owner triplet is empty, the group triplet is never consulted for you, even when you are a member of the group. This rule is the most common cause of a surprising denial.

Step three: root and capabilities

A process with effective UID 0 skips the check for most access. In the modern model this bypass is a capability, named CAP_DAC_OVERRIDE for writing and reading, together with CAP_DAC_READ_SEARCH for reading and searching. A process that holds the capabilities acts as root for these checks even when its UID is not zero. Root has them all, and a normal account has none of them. Some operations still require specific capabilities, such as changing the owner of a file.

This model explains the earlier rule that only root may give a file to another user. Changing the owner requires a capability that an ordinary account does not hold. The kernel checks for the capability, finds it missing, and returns an error. No mode change can fix that, because it is a different check from the mode.

Extra layers that change the answer

Two extra layers can change the result. Access control lists, or ACLs, add named user and named group entries to a file, so a single file can grant access to a particular account without changing the owner or group. A file with an ACL still has the classic mode bits, and the ACL entries are checked as well. The second layer is the sticky bit on a directory, which restricts deletion as described in the previous unit.

Mount options can also change the answer. A file system mounted read-only refuses writes for everyone, including root, and a file system mounted with noexec refuses to run programs from it. These checks happen before the mode is even considered. When a file looks correct but still fails, check the mount options with the mount command, and check the mode second.

Reading a denial in practice

When an access fails, work through the same sequence in order. First check search permission on every directory from the top down to the file. Second, find out whether your effective UID owns the file, and if not, whether any of your group IDs match its group. Third, read the matching triplet and see which bit is missing. Finally, check whether the file system is mounted read-only. Following these four steps finds the real cause, and it stops you from changing the mode of the file when the actual problem is a directory above it.

BASH2 lines
id
stat -c "%A %u %g %n" /workspace

The first command gives your identity, and the second gives the owner and group of a directory on the path. Together they answer the first two steps for that directory. Repeat the pattern up the tree, and the place where the answer changes is the place to fix.

Why the order matters

The order of the checks explains why some fixes work and others do not. Making a file writable does nothing if its directory blocks search, because the kernel never reaches the file. Adding a user to a group does nothing for a process that was started before the change, because its group list was fixed at login. Knowing the order lets you choose the one change that the kernel will actually use.

How the kernel decides who may access a file

Visualizer

The kernel picks one class (owner, group or other) and uses only that class’s bits. Directories read r, w and x differently, and the sticky bit limits who can delete.

1 / 4
-type
-owner
-
-
rgroup
w
x
-other
-
-
process
uid 1000, gid 1000
file
owner 1000, group 1000
mode
070

The kernel knows the process’s uid and gid, and the file’s owner and group. It picks exactly one class for the check and tries them in order: owner, group, other.

cd "$(mktemp -d /tmp/perm.XXXX)" && touch own.txt && chmod 070 own.txt && cat own.txt; echo "status $?"; stat -c "%a %A" own.txt
Check yourself Question 1 of 4
Concept Check Bypassing the checks recall

Which effective UID bypasses most discretionary permission checks?

Recap & Key Takeaways

The kernel walks the path and needs search permission on each directory before it looks up the next name.
For the final object, the kernel picks the owner, group, or other triplet by the first match, and it does not combine them.
Effective UID 0, or the matching capabilities, bypasses most of the discretionary checks, and chown needs a capability that normal accounts lack.
When an access fails, check the path, then the identity and class, then the missing bit, and finally the mount options.
Was this lesson helpful? Spot an issue or have a suggestion? Let us know on GitHub.
Report an issue