Lesson 3 of 10Foundations

12 min · theory and practice · Basics

Permissions and ownership: tracing Permission denied

Check access as the service user, including every directory on the path.

Distinguish a missing file, a blocked directory traversal and missing write access.

Root can read a file, yet an application or cron job fails with Permission denied. Those are different access contexts. Identify the process user, actual path and operation: reading, creating a backup or replacing a result. Test the operation the service is failing to perform.

Identify the effective user

Inspect User and Group in the unit, then the running process owner. A system unit without User normally runs as root; the application name does not establish its identity. A job in /etc/cron.d has a separate user field in its schedule.

Commands
systemctl show shop-api -p User -p Group -p MainPID
ps -eo pid,user,group,args | head -n 15
id backup

In the backup case, inspect the backup user rather than your administrative shell.

Inspect every path component

Accessing a file requires search permission on every parent directory: the directory x bit. Directory r permits listing names; w together with x permits creating and removing entries. A permissive final file cannot compensate for an inaccessible parent.

Commands
namei -l /var/backups/shop
ls -ld /var /var/backups /var/backups/shop
stat -c "%A %U:%G %n" /var/backups/shop
Example output
drwx------ root root /var/backups
drwxrwx--- backup backup /var/backups/shop

Here backup cannot traverse /var/backups even if the child belongs to it. This illustrates permission interpretation, not a repair for a particular variant.

Reproduce access without unnecessary writes

sudo -u runs a command as the intended user. test -r and test -w help check expected access, but the real job succeeding is the final proof. ACLs, read-only mounts and systemd restrictions can also affect access, so mode bits are a starting point.

Commands
sudo -u backup test -r /var/lib/shop/shop.sqlite3
sudo -u backup test -w /var/backups/shop

test prints nothing: inspect its exit status with echo $?. In the case, use paths from the job configuration.

Repair the narrow access boundary

Choose the intended owner or group and only the necessary permissions. chmod 777 can hide the failure while exposing data to other users. Avoid blanket recursive changes: the tree may contain secrets and customer uploads.

Publishing through rename requires access to the destination directory. Reading the source and executing the script are separate checks.

Verify through the actual launcher

After the change, verify the same systemd unit or next cron run. Check that the result has the intended owner and can be read by its consumer without granting universal access. Do not replace the normal user with root merely to pass a check.

From symptom to check

ObservationNext checkHow to interpret it
Root reads the file; backup cannotid, namei and test -r as backupInspect the effective identity and traversal of every directory.
Script reads the DB but creates no backupDestination-directory permissionsReading a source and creating a result are different operations.
Mode bits look correct; access still failsACLs, mounts and unit restrictionsInspect launch context and additional restrictions.

Common mistakes

  • Applying chmod -R 777 to an entire tree.
  • Changing file permissions without inspecting an inaccessible parent.
  • Testing only as root and ignoring the normal user.

How to prove recovery

  1. Verify backup can read the source database.
  2. Verify the normal job creates and publishes its result.
  3. Inspect the new copy’s owner and permissions.
  4. Verify unrelated users were not granted access.

MINI INCIDENT

Why are final-directory permissions insufficient?

The shop directory belongs to backup and permits writing. Its parent /var/backups is inaccessible to others. Why can cron still not create a backup?

Evidence to investigate
/var/backups       root:root     drwx------
/var/backups/shop  backup:backup drwxrwx---
Explore the diagnosis

Path traversal stops at the parent: backup lacks search permission on /var/backups. Establish the intended narrow user/group access boundary, then run the real job. Broad permissions on shop cannot repair the inaccessible path.

WORKSHOP

Workshop: explain the evidence and choose an action

The configuration file is readable by everyone, but backup cannot reach it. Examine every boundary along the path.

Sample evidence
/opt              drwxr-xr-x root root
/opt/backup       drwx------ root root
/opt/backup/conf  drwxr-xr-x root root
backup.conf      -rw-r--r-- root root
  1. Where is the first verified barrier?

    Compare your reasoning

    /opt/backup denies traversal to backup unless another permission mechanism grants it. The final file’s read bits cannot help because path lookup stops earlier.

  2. How can the failure be reproduced without running the full backup?

    Compare your reasoning

    Use namei -l and a targeted test -r as backup. Configuration access, source reading and destination writing use separate paths and need separate checks.

  3. How can a minimal change be justified?

    Compare your reasoning

    Name the user, required operation and boundary denying it. Use an appropriate group or narrow permission, then repeat the probe and scheduled execution.

CHECK YOUR UNDERSTANDING

Why did chmod 644 on the file fail to let backup read it?

Show explanation

A parent directory may lack x, or an ACL or service restriction may apply. Inspect the whole path and test the actual operation as backup.

Documentation

Guest progress is stored separately in this browser.

TAKE IT TO THE TERMINAL

Practice on an incident

Apply identity-aware access checks to application startup, scheduled backups and static files.

DID IT MAKE SENSE?

Was this article helpful?

Rate the article or tell us what needed more explanation. Your feedback helps improve the lessons.

Helpful 0 Not helpful 0

Sign in to rate this article and leave a comment.

Discussion

1

Join the discussion →

hyi

Не хватает дополнения по типу "смотри логи"