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/tmpand deleted afterwards. The full background is in our Linux file permissions guide.
Contents
- 1. The quick fix
- 2. Find out who says no: ls -l and id
- 3. Why it happens: owner, group, others
- 4. Cause 2: a folder without x
- 5. Cause 3: a parent folder you do not control
- 6. The three checks, in order
- 7. How to prevent it
- Frequently asked questions
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
ls -l file: who owns it and which letters does it have?namei -l /full/path: does every folder give youx?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
644and folders with755: the owner writes, everybody else reads and enters. - Run
ls -lafter 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.
More tutorials like this
systemd Basics: Manage Services and Read Logs with systemctl and journalctl
Start, stop and enable services with systemctl, read logs with journalctl, write your own service and timer, and troubleshoot a service that will not…
Bash Scripting for Beginners: Variables, Loops, Functions and Exit Codes
Learn Bash scripting from your first script to a safe backup script: variables, quoting, loops, functions, exit codes and set -euo pipefail, with real…
Linux Processes: ps, top, kill, nice and Background Jobs Explained
List and sort processes with ps and top, stop them safely with kill signals, set priority with nice, and keep long jobs running with…



