PREP WITH PROOF
Menu
LINUX & INFRASTRUCTURE / PRACTICAL GUIDE

Linux Permission Denied: Files, Directories and umask

Trace Linux Permission denied errors through identity, parent directory search, file modes, ACLs and umask. Includes a tested Python permissions lab without access-bypass capabilities.

THE QUICK ANSWER

Diagnose Linux Permission denied by matching the failed operation to the process identity, every parent directory and the target object. File read/write, directory search and directory-entry changes require different permissions. umask affects new objects; ACLs and other policies can add further checks.

Start with the operation that failed

A service can read a report but fail to replace it. A user can list a directory yet fail to open a file inside it. A script can work in a terminal and fail when launched by a service manager. These are useful clues, not contradictions. Each operation asks the kernel for different access, under the identity and filesystem view of the process that performs it.

Before changing permissions, capture the exact pathname, operation and error. “Cannot save” might mean opening an existing file for writing, creating a temporary sibling, renaming it over the original, or removing an old version. An editor using replace-by-rename has different directory requirements from a program appending to the existing inode. Diagnose the actual action rather than the button label.

This guide concerns ordinary local Linux files and directories. It separates traditional mode bits, path traversal, creation defaults and additional enforcement layers. The commands inspect one named path; substitute a path you administer. The laboratory uses only disposable temporary files and is deliberately run without elevated discretionary-access capabilities.

Establish whose permissions are being evaluated

Run id in the same execution context as the failing process. Your interactive account is not evidence of a service account’s identity or supplementary groups. On a conventional host, inspect the service configuration and its running process. In a container, inspect the identity and mount visible inside that container; a host username and a container username can map to different numeric IDs.

Use a numeric ownership listing to avoid confusing names with IDs. Then inspect every directory in the path with namei. In the example, making report.csv readable does not help if the process cannot traverse /srv/reports/private. Also inspect symbolic-link targets: the visible shortcut may lead into a different ownership tree.

The following are inspection commands, not permission changes. namei comes from util-linux and may be absent on minimal images. If it is unavailable, list each parent directory explicitly. An inability to inspect a component is itself relevant evidence; do not assume the final file is the only blocked object.

id
ls -ldn -- /srv /srv/reports /srv/reports/private
ls -ln -- /srv/reports/private/report.csv
namei -l /srv/reports/private/report.csv

Source: util-linux namei: path inspection ↗

Read the matching class, then interpret the object

In a basic mode such as 0640, the three permission digits apply to owner, group and other. Each digit combines read=4, write=2 and execute=1. For ordinary discretionary checks without an extended ACL, an owner uses the owner class; otherwise a matching group uses the group class; otherwise other applies. These classes are not a pool from which the process chooses the most generous result.

That distinction explains a surprising test: if you own a file with mode 0004, the other-read bit does not rescue the missing owner-read bit. Linux capabilities and ACLs can change the broader analysis, so use the simple class rule only after checking whether those mechanisms matter.

The meaning of a permission also depends on the object. Directory execute means search or traversal, not “run this folder.” Permission to search every parent is needed to reach a known file. Directory read lets you enumerate names; obtaining metadata or opening those names introduces further checks.

PermissionRegular fileDirectory
rRead file contentsEnumerate entry names
wModify file contentsChange entries, normally with search permission too
xPermit direct execution, subject to other execution checksSearch known names and traverse the directory

Source: Linux inode: file modes and ownership ↗

Explain read, create and delete separately

A directory with read but no search permission can reveal names while preventing access to a named child. Conversely, search without read can let a process open a known child while preventing directory enumeration. That is why a successful ls of names is not a sufficient read-access test, and a failed listing does not prove that every known child is inaccessible.

To modify an existing file in place, inspect that file’s write permission as well as the traversal path. To create a new file, inspect the containing directory. To remove a directory entry, the relevant ordinary permissions are write and search on its parent; file write permission is not the controlling check. A read-only file may therefore be removable by someone permitted to change the parent directory.

The sticky bit adds a deletion restriction in shared directories, commonly seen as t in /tmp permissions. It is one reason the simple directory-write rule is not the whole deletion policy. A read-only filesystem, immutable attributes or another policy can also stop a change even when the ordinary mode bits look sufficient.

Source: Linux unlink: directory permissions and deletion restrictions ↗

Reproduce the boundaries in a temporary directory

Save this as permission_lab.py and run python3 permission_lab.py from an ordinary Linux account. Do not use sudo. Run the code as written, without Python’s -O option, because it uses assertions. It creates a fresh temporary directory, changes only its own objects and cleans them up afterward.

The expected final line is “PASS: 11 checks.” We executed this exact script locally in a Linux process without CAP_DAC_OVERRIDE or CAP_DAC_READ_SEARCH (UID 0 in this isolated runtime). It demonstrates traversal versus listing, matching-owner behavior, creation denial, deletion of a read-only child, and modes produced by a creation mask. No production service, ownership tree or security policy was changed.

The creation-mode assertions assume the temporary directory has no inherited default ACL that changes the result. If the script fails there, inspect the temporary filesystem’s ACL policy before changing the expected values. Run it in a separate process: os.umask changes process-wide state, so this is not a pattern for temporarily changing masks inside a multithreaded application.

import os
import stat
import tempfile
from pathlib import Path

with open("/proc/self/status", encoding="ascii") as status:
    caps = next(line.split()[1] for line in status if line.startswith("CapEff:"))
if int(caps, 16) & 0b110:  # CAP_DAC_OVERRIDE or CAP_DAC_READ_SEARCH
    raise SystemExit("Run without discretionary-access bypass capabilities")

checks = 0

def check(condition):
    global checks
    assert condition
    checks += 1

def denied(operation):
    global checks
    try:
        operation()
    except PermissionError:
        checks += 1
    else:
        raise AssertionError("Expected PermissionError")

with tempfile.TemporaryDirectory(prefix="permission-lab-") as temp:
    base = Path(temp)
    parent = base / "reports"
    parent.mkdir(mode=0o700)
    item = parent / "report.txt"
    item.write_text("example\n", encoding="utf-8")
    item.chmod(0o600)
    try:
        check(item.read_text() == "example\n")
        parent.chmod(0o600)  # r+w, but no directory search
        check("report.txt" in os.listdir(parent))
        denied(item.read_text)
        parent.chmod(0o100)  # search, but no name listing
        check(item.read_text() == "example\n")
        denied(lambda: os.listdir(parent))
        parent.chmod(0o700)
        item.chmod(0o004)  # owner does not fall back to other
        denied(item.read_text)
        item.chmod(0o400)
        parent.chmod(0o500)
        denied(lambda: (parent / "new.txt").touch())
        parent.chmod(0o700)
        item.unlink()  # directory permits removal of a read-only file
        check(not item.exists())
        old_mask = os.umask(0o027)
        try:
            created = parent / "created.txt"
            with created.open("x"):
                pass
            folder = parent / "created-dir"
            folder.mkdir(mode=0o777)
        finally:
            os.umask(old_mask)
        check(stat.S_IMODE(created.stat().st_mode) == 0o640)
        check(stat.S_IMODE(folder.stat().st_mode) == 0o750)
        check(stat.S_IMODE(parent.stat().st_mode) == 0o700)
    finally:
        parent.chmod(0o700)  # restore traversal for temporary cleanup
print("PASS:", checks, "checks")

Treat umask as a creation filter, not a repair command

An application requests a mode when creating an object. With no default ACL, the creation mask removes requested permission bits: requested_mode & ~umask. For the usual regular-file request of 0666 and a mask of 0027, the result is 0640. A directory requested as 0777 becomes 0750. The mask cannot add executable permission that the application never requested.

Changing umask affects subsequent creations in that process and its descendants; it does not rewrite existing objects. This explains a common deployment mismatch: old files remain readable, but files created by a new service configuration are too restrictive. Inspect the creating process’s settings and a newly created object, not only your current shell’s umask.

A parent’s default ACL changes the creation calculation. Also, programs may request a stricter mode or apply chmod afterward. Treat the observed mode as the outcome of the whole creation workflow. A default ACL, service setting and application behavior should be reviewed together before deciding that a shell profile is the cause.

# Shows the current shell setting; not necessarily the service setting.
umask
umask -S

# Inspect an existing object without modifying it.
stat -c "%a %u:%g %n" -- /srv/reports/private/report.csv

Source: Linux umask: creation permissions and default ACLs ↗

If the basic explanation fails, inspect ACLs and policy

An extended access ACL can grant named users and groups permissions beyond the basic owner/group/other entries. The ACL mask limits named-user and group-class entries; a visible rwx entry may therefore have fewer effective rights. getfacl shows those entries and, where applicable, effective annotations. A default ACL on a directory concerns inheritance for new objects, not a retroactive grant to all existing children.

Run the inspection below only if the ACL utilities are installed. Do not erase an ACL just to make the display simpler. Record the complete existing policy and identify the entry involved. Changing the group mode bits with chmod can affect an ACL’s mask, so a seemingly small mode change deserves reinspection when an extended ACL is present.

If discretionary permissions and ACLs permit the operation, investigate the next evidenced layer: a read-only or noexec mount, SELinux or AppArmor enforcement, service sandbox restrictions, network-filesystem identity rules, or an immutable attribute. Use the system’s relevant diagnostics and denial records. A mode change cannot repair a mount policy or a service seeing a different path.

getfacl -p /srv/reports/private
getfacl -p /srv/reports/private/report.csv

Source: Linux ACL access checks, masks and inheritance ↗

Execution failures need their own branch

A readable script is not necessarily directly executable. Running ./job.sh requests execution of that file; running bash job.sh asks bash to read the script. The second form is a different operation, not proof that direct execution is correctly configured. Check the script mode, traversal path and intended interpreter before deciding which behavior the application requires.

A direct-execution failure may also involve a noexec mount, a missing or inaccessible interpreter, or a policy denial. A misleading-looking “No such file or directory” can refer to the interpreter named by a script rather than the script itself. Inspect the first line and the interpreter path. Do not classify every failed launch as a chmod problem.

Source: Linux execve: execution and interpreter errors ↗

Make one justified change and verify the original operation

Choose the intended access model before editing it: owner-only data, a shared operational group, or an explicit named-user ACL. Then change only the object and permission responsible for the failure. For example, adding group search to a known directory can be appropriate when that group is deliberately allowed to traverse it; it is not a reason to grant group read access to every file underneath.

Avoid a recursive chmod 777 as a diagnostic step. It grants broad access, changes evidence and can introduce unrelated executable files. A recursive chown can also disrupt service and deployment ownership. Even a successful retry after a broad change does not identify the minimum permission required or prove the access model is acceptable.

Retest the exact failed operation under the same service identity and mount context. Also test an identity that should remain denied. Check newly created files after a service restart or deployment, and verify ACLs again if present. Record the path, operation, chosen policy and resulting modes so the next deployment does not silently recreate the problem.

The evidence that closes the incident

A useful resolution explains which process attempted which operation on which path, which component denied access, and why the narrow change matches the intended policy. Reading a file, replacing it and creating its successor should each be tested if the application performs all three.

If the actual error is a full filesystem or exhausted inodes, follow the related disk-capacity guide. If a Python script is launching with the wrong interpreter, use the environment guide. Keeping those diagnoses separate prevents permission changes from becoming a general-purpose response to unrelated failures.

KEEP THESE THREE THINGS

Your next steps

  1. Check the actual service identity and every path component before editing the final file.
  2. Directory listing, traversal and entry changes are separate operations.
  3. Verify a narrow repair and the modes of newly created files; avoid broad recursive changes.

Sources & official resources

Linked resources checked on 2026-10-25. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →