Linux Permission Denied Error: Causes and How to Fix It (chmod, namei, id)

Linux 5 min readUpdated Nov 25, 2026
0 views0 comments

You run a simple command and Linux answers:

$ cat /etc/shadow
cat: /etc/shadow: Permission denied

“Permission denied” means Linux checked who you are, looked at the permission letters of the file (and of every folder on its path), and found no letter that lets you do what you asked. Nothing is broken and no data is lost. This guide shows the quick fix, explains how Linux decides, and walks through the three most common causes with the commands to check each one.

Part of the Linux Errors and How to Fix Them series. Every output below was captured on an AlmaLinux 9 lab machine; account names are replaced by your-user. The test files were created in /tmp and deleted afterwards. The full background is in our Linux file permissions guide.


Contents

1. The quick fix

Look at the permissions of the file, then add only the letter you are missing. Here is a file owned by the user who cannot read it:

$ ls -l report.txt; cat report.txt
----------. 1 your-user your-user 27 Nov 18 23:24 report.txt
cat: report.txt: Permission denied

Ten dashes: nobody has any permission, not even the owner. Give the owner the read permission:

$ chmod u+r report.txt && ls -l report.txt && cat report.txt
-r--------. 1 your-user your-user 27 Nov 18 23:24 report.txt
quarterly report: 42 units

u+r means “user (owner), add read”. Use g for the group, o for others, w for write and x for execute or enter.

2. Find out who says no: ls -l and id

$ ls -l /etc/shadow
----------. 1 root root 1023 Nov 15 18:34 /etc/shadow

$ id
uid=1000(your-user) gid=1000(your-user) groups=1000(your-user) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

The file belongs to root and has no permissions at all, so only root (who skips these checks) can read it. You are user 1000, not the owner and not in the group. This is on purpose: the file holds password hashes. On a server where you are an administrator, use sudo cat /etc/shadow; a normal account is meant to be denied.

3. Why it happens: owner, group, others

Every file has three sets of permissions: owner, group and others, each with r (read), w (write) and x (execute, or enter for a folder). Linux checks you in that order and the first set that matches decides. If that set lacks the letter you need, you get Permission denied. No letter, no access.

4. Cause 2: a folder without x

A file can be fine and still unreachable, because every folder on the path needs x so that you can walk through it.

$ cat locked/note.txt
cat: locked/note.txt: Permission denied

$ namei -l locked/note.txt
f: locked/note.txt
drw------- your-user your-user locked
                             note.txt - Permission denied

namei -l prints every step of the path. The folder locked is drw-------: no x. Add it:

$ chmod u+x locked && cat locked/note.txt && ls -ld locked
hello
drwx------. 2 your-user your-user 22 Nov 18 23:24 locked

5. Cause 3: a parent folder you do not control

$ ls /root
ls: cannot open directory '/root': Permission denied

$ ls -ld /root
dr-xr-x---. 5 root root 4096 Nov 16 14:14 /root

$ namei -l /root/.bashrc
f: /root/.bashrc
dr-xr-xr-x root root /
dr-xr-x--- root root root
                     .bashrc - Permission denied

Others get three dashes on /root, so every file inside is unreachable for you, whatever its own permissions are. Ask an administrator, or use sudo if your account has it (on the lab account used here, sudo asks for a password, so the command was not run).

6. The three checks, in order

  1. ls -l file: who owns it and which letters does it have?
  2. namei -l /full/path: does every folder give you x?
  3. id: are you the owner, in the group, or a stranger?

If all three look right and it still fails, check SELinux (getenforce, ls -Z file) and mount options such as read-only file systems.

7. How to prevent it

  • Create files with 644 and folders with 755: the owner writes, everybody else reads and enters.
  • Run ls -l after a copy or an unzip, before a script uses the files.
  • Keep scripts and their data in folders owned by the account that runs them.
  • Never fix it with chmod 777: it gives every account and every hacked service full control. Add one letter at a time.

Frequently asked questions

Why does cat say Permission denied on my own file?

Because Linux obeys the permission letters, not who created the file. If the owner block has no r, even the owner cannot read it. Fix it with chmod u+r file.

Is sudo the fix?

Only when the file really belongs to another user such as root and you are allowed to use it. For your own files, change the permissions instead.

Why does ls work on a file but cat fails inside a folder?

Listing a name needs r on the folder; reaching the file inside needs x. Check the path with namei -l.

Did you find this helpful?Tap the heart to let us know. It takes one second and no account.

More tutorials like this

Leave a Comment

Your email address will not be published. Required fields are marked *

Bigland Network IT

Practical tutorials for people who run, build and fix things: operating systems, databases, development, networking and security.

Topics

More

Site

© 2026 Bigland Network. All rights reserved.Always test commands on a non-production system first.
Scroll to Top