Linux "Permission Denied": Diagnose It Fast
A likelihood-ordered checklist for tracing "Permission denied" on Linux through mode bits, ownership, ACLs, SELinux, and mount options.
Key takeaways
- Linux denies access when the one permission class that applies to you (owner, group, or other) lacks the bit you need.
- Compare ls -l with id, then run namei -l on the path to find a parent directory without execute.
- If those look fine, check ACLs, SELinux or AppArmor labels, and noexec or read-only mounts.
On this page
To fix "Permission denied" on Linux, compare ls -l <file> against id, then run namei -l <path> to catch a parent directory you cannot traverse. Those two steps solve most cases. If the bits look right, check for an ACL (+ after the mode), an SELinux or AppArmor denial, and a noexec or read-only mount, in that order.
Verified against
Linux man-pages 6.19 (path_resolution, acl), util-linux namei, against man7.org and the Red Hat Enterprise Linux 9 SELinux troubleshooting guide. Checked October 2026.
Resist chmod 777. It often "fixes" the symptom, which is exactly why it is dangerous: you never learn what was wrong, and you leave a world-writable file for the next person. Work the list below top to bottom and stop at the first hit.
The 30-second triage
Run these four commands before you change anything. Between them they cover every layer in this post:
$ ls -l /srv/app/deploy.conf # mode, owner, group (and + for ACL, . for SELinux)
$ id # who you are, which groups this session has
$ namei -l /srv/app/deploy.conf # mode of every directory on the path
$ findmnt -no OPTIONS -T /srv/app # noexec, ro, nosuid on the containing mount
1. Mode bits and ownership
$ ls -l deploy.conf
-rw-r----- 1 root deploy 812 Jul 20 14:02 deploy.conf
$ id
uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo)
Owner root gets read/write, group deploy gets read, everyone else gets nothing. Alice is neither, so she lands in "other". The kernel picks exactly one class: owner if your effective UID matches, else group if one of your groups matches, else other. Per the path_resolution(7) man page, it does not fall through to a more permissive class, so an owner with --- is denied even when "other" has rwx.
Fix the principal, not the world:
$ sudo usermod -aG deploy alice # -a appends; without it you lose other groups
$ newgrp deploy # or log out and back in
$ sudo chgrp deploy deploy.conf # alternatively, fix the group ownership
Group membership is read at login, which is why usermod appears not to work until you start a new session. The same mechanism trips up Docker users; our Docker permission denied fix walks through that variant.
2. A parent directory without execute
On a directory, x means "search": you may traverse it. Without x on every parent, you cannot reach the leaf, even if the file itself is 0644.
$ cat /srv/app/secrets/token
cat: /srv/app/secrets/token: Permission denied
$ namei -l /srv/app/secrets/token
f: /srv/app/secrets/token
drwxr-xr-x root root /
drwxr-xr-x root root srv
drwxr-x--- root app app
drwxr-xr-x root app secrets
-rw-r--r-- root app token
app is drwxr-x--- and you are not in group app, so the walk stops there. namei -l is the single most useful command for "but the file permissions look fine". Grant x to the right group on that one directory (chmod g+x, or chmod o+x if traversal by anyone is acceptable); you do not need r, which would also let people list it.
3. Running a script without the execute bit
$ ./backup.sh
bash: ./backup.sh: Permission denied
$ chmod u+x backup.sh
Read the exact wording before reaching for chmod. bash: ./backup.sh: cannot execute: required file not found is a different failure: usually a bad shebang path or CRLF line endings (sed -i 's/\r$//' backup.sh). bash backup.sh working while ./backup.sh fails points at the execute bit or a noexec mount (section 6).
4. ACLs
A trailing + in ls -l means POSIX ACLs are in play:
$ ls -l report.csv
-rw-rw----+ 1 finance finance 1841 Jul 19 22:31 report.csv
$ getfacl report.csv
# file: report.csv
# owner: finance
# group: finance
user::rw-
user:alice:---
group::rw-
mask::rw-
other::---
$ sudo setfacl -m u:alice:rw report.csv
A named-user entry like user:alice:--- wins over Alice's group membership. Also watch the mask line: per acl(5), named users, named groups and the owning group are capped at the mask, so mask::r-- silently turns every rw grant into read-only. A plain chmod g-w on an ACL file changes the mask, not the group entry, which surprises people.
5. SELinux and AppArmor
The classic tell: bits, ownership and ACLs are all correct, and it still fails, until someone runs setenforce 0. That is a label problem.
$ ls -Z /var/www/html/index.html
unconfined_u:object_r:user_home_t:s0 /var/www/html/index.html
$ sudo ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent
type=AVC msg=audit(...): avc: denied { read } for pid=1123 comm="httpd"
name="index.html" scontext=system_u:system_r:httpd_t:s0
tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0
$ sudo sealert -l "*"
$ sudo restorecon -v /var/www/html/index.html
The file was mv'd from a home directory and kept user_home_t; Apache needs httpd_sys_content_t. restorecon resets the label to policy default, which fixes most of these. For a non-standard path, add a rule first (semanage fcontext -a -t httpd_sys_content_t "/srv/myweb(/.*)?") and then run restorecon -R -v /srv/myweb. Red Hat's guide recommends journalctl -t setroubleshoot when ausearch finds nothing, and warns against reaching for audit2allow as a first option. setenforce 0 is a diagnostic, not a fix.
On Debian and Ubuntu, the equivalent is AppArmor: sudo aa-status, then journalctl -k | grep 'apparmor="DENIED"' to see the profile and the blocked path.
6. Mount options
$ ./tool
bash: ./tool: Permission denied
$ findmnt -no OPTIONS -T ./tool
rw,nosuid,nodev,noexec,relatime
noexec blocks execution regardless of the x bit, and it is common on hardened /tmp, /home and removable media. Copy the binary elsewhere or ask whether the mount should allow it. A write to a read-only mount reports Read-only file system (EROFS) instead of permission denied, which is your cue to check findmnt rather than chmod.
7. Readable but not writable
$ ls -l app.log
-rw-r--r-- 1 root adm 9210 Jul 21 11:44 app.log
$ echo x >> app.log
bash: app.log: Permission denied
$ echo x | sudo tee -a app.log
Read and write are separate bits, and your class grants only one. Note that sudo echo x >> app.log still fails: the redirect is performed by your unprivileged shell, not by sudo. sudo tee -a is the correct form. If the fix really is a mode change, the chmod calculator translates octal and symbolic modes and flags world-writable results.
Where this breaks
This checklist covers local filesystems. Network filesystems add their own layer: NFS with root_squash maps root to nobody, so even sudo gets denied, and the server's export rules matter more than local bits. Containers add user-namespace UID remapping, so the UID inside does not match the owner you see on the host. Capabilities (CAP_DAC_OVERRIDE) and immutable files (lsattr showing i, fixed with chattr -i) also sit outside mode bits. For broader method, start from the Linux troubleshooting guide.
Questions people ask
Why do I get permission denied even with sudo?
Three usual causes. A shell redirect like sudo cmd > file opens the file as you, not root; use sudo tee. On NFS, root_squash maps root to an unprivileged user. And SELinux or AppArmor can deny root too, because mandatory access control applies regardless of UID. Check ausearch -m AVC -ts recent or the journal for apparmor="DENIED".
How do I find which directory is causing permission denied?
Run namei -l /full/path/to/file. It prints the mode, owner and group of every component from / down to the file. Look for the first directory where your user, through the owner, group or other class that applies, lacks the x (search) bit. That directory blocks the whole path, regardless of how permissive the file itself is.
Is chmod 777 ever the right fix?
Almost never. It makes the file writable by every account and process on the machine, which turns any compromised service into a way to tamper with it, and it hides the real cause. The rare legitimate case is a scratch directory, and even there /tmp uses 1777, adding the sticky bit so users cannot delete each other's files.
The call we'd make
Run the four triage commands, then work top to bottom and stop at the first hit. Nine times in ten it is a mode or ownership mismatch you can read straight from ls -l and id, and namei -l catches the parent-directory cases. Only after those come out clean should you suspect the + of an ACL or the . of an SELinux label. Fix the specific principal being denied, relabel with restorecon instead of disabling policy, and never ship chmod 777. For a deeper reference on the bits themselves, read Linux file permissions explained.
Sources
Cite this article
Kiril Urbonas (2026). Linux "Permission Denied": Diagnose It Fast. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/fix-permission-denied-linux
[Linux "Permission Denied": Diagnose It Fast](https://www.devopsness.com/blog/fix-permission-denied-linux) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Linux
Explore more articles in this category
CVE-2026-98432: The CVSS 9.8 Linux TCP Bug Now Has an Exploit. Patched Node Images
A use-after-free in the IPv4 TCP handshake, present since Linux 4.4, now has a working exploit against MPTCP listeners, and every Go 1.24+ server is one by default. Which kernels are fixed and how to roll them through EKS, GKE and AKS.
CERN Left Red Hat for Debian: The CPU Baseline Lesson
CERN is moving accelerator control computers to Debian because RHEL raised its minimum CPU level. Check your own fleet's x86-64-vN support before the next OS upgrade does it for you.
ext4 vs XFS vs Btrfs: Choosing a Filesystem for a Server
The default filesystem your distro picks is not always the right one for your workload. Here is what actually differs and when each one wins.
You might have missed
Evergreen posts worth revisiting.