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.
systemctl show shop-api -p User -p Group -p MainPID
ps -eo pid,user,group,args | head -n 15
id backupIn 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.
namei -l /var/backups/shop
ls -ld /var /var/backups /var/backups/shop
stat -c "%A %U:%G %n" /var/backups/shopdrwx------ root root /var/backups
drwxrwx--- backup backup /var/backups/shopHere 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.
sudo -u backup test -r /var/lib/shop/shop.sqlite3
sudo -u backup test -w /var/backups/shoptest 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
| Observation | Next check | How to interpret it |
|---|---|---|
| Root reads the file; backup cannot | id, namei and test -r as backup | Inspect the effective identity and traversal of every directory. |
| Script reads the DB but creates no backup | Destination-directory permissions | Reading a source and creating a result are different operations. |
| Mode bits look correct; access still fails | ACLs, mounts and unit restrictions | Inspect 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
- Verify backup can read the source database.
- Verify the normal job creates and publishes its result.
- Inspect the new copy’s owner and permissions.
- 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?
/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.
/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 rootWhere 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.
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.
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.
Не хватает дополнения по типу "смотри логи"