Permission denied — file access denied due to ownership or mode
Permission denied when accessing a file or directory
Focused incident mode — strips away everything but this runbook.
Symptoms
- Permission denied when accessing a file or directory
- Application fails with EACCES error
- Cannot read/write to a file you expect to have access to
Evidence to grab
Collect these artifacts before you change anything — they prove (or rule out) each cause.
File ownership and permissions
ls -la <path> && stat <path>Process user and groups
id <user> && groups <user>
Diagnostic flow
Run the steps in order, marking each claim confirmed or refuted. The evidence you gather feeds the ranked causes below.
Guided decision tree is ready.
Steps with commands, expected output, and pass/fail branches.
Ranked root causes
Evidence checklist
- ls shows the file owned by root instead of the application user
- Application was installed as root but runs as a service user
Confirm before fixing
ls -la <path>Check the UID and GID
Fix
chown <user>:<group> <path>Change the file ownership to the correct user
Resolution runbook
Apply from top to bottom after the cause is confirmed. Review every command before running it — risk tags are shown on each.
ls -la <path> && stat <path>Check file ownership and permissions
ps -p <PID> -o user,group,cmdCheck which user the process runs as
chown <user>:<group> <path> && chmod <mode> <path>Fix ownership and permissions
getenforce 2>/dev/null && ausearch -m avc --ts recent | tail -5Check for SELinux denials
Prevention
- Document the required file ownership and permissions for each service in a deployment runbook.
- Use Ansible/Chef/Puppet to enforce file permissions consistently.
- Set umask in service unit files so created files have correct defaults.
- Test permission changes in staging before applying to production.
Related runbooks
Same stack, same failure family — worth a skim.
Commands marked READ CHANGE DESTRUCTIVE — never run DESTRUCTIVE commands against production data you cannot restore. Copy → verify → execute.