Permission denied in Linux: 10 cases including /dev/null

Test environmentRHEL familyAlmaLinux 9.8root accountDebian 12 regular accountChecked 2026-11-05
Finding the cause of Permission denied

Permission denied is a Linux error that appears when your current account has no permission to use that file, folder, or command. Pick your case from the command name and path at the start of the error line, check the permissions and owner with ls -l, and run it again with the right permissions or account to fix it.

The output below comes from the root account on an AlmaLinux 9.8 server and a regular account on a Debian 12 server; account and host names and the timestamps in the /dev/null output are example values.

1️⃣ Finding the cause of Permission denied

An error line ends in the form [command: target: Permission denied], and the command name and path in front of it show where it was blocked. In the diagram below, pick the error message that looks like the one on your screen to see the command to check first and where to read in this article.

🧭 Find your case by the error message
Explainer diagram
🧭 Error message
Error messagecat: secret.txt: Permission deniedls: cannot access 'web/index.html': Permission denied./deploy.sh: Permission deniedls: cannot open directory '/proc/1/fd': Permission deniedbash: /root/test.txt: Permission denieduser@server1: Permission denied (publickey)(13)Permission denied-bash: /dev/null: Permission denied
➜
Check firstls -l secret.txtls -ld webls -l deploy.shidsudo sh -cHome folder and file permissionsgetenforce · findmntls -l /dev/null
➜
Where in this article🔲 File read and write permissions🔲 Folder traverse permission🔲 Execute permission🔲 Reading root-only information🔲 When > is blocked even with sudo🔲 SSH login refused3️⃣ Rare Permission denied errors🔲 When /dev/null has become a regular file
If a command that reads or changes a file is refused, first check that file's r and w permissions and its owner.
If the name of a folder in the middle of the path appears in the error, check whether that folder has the x permission.
If running a script directly is refused, check whether the file has the x permission.
If reading system information as a regular account is blocked, check the current account and run it again as root.
If a > redirection is blocked even with sudo, run the redirection as root too.
If the account and server address come before the error, the login was refused at authentication.
If it is refused even though the permission bits are right or you ran it as root, check SELinux, noexec, and the execute bits.
If this line repeats right after you log in, check whether /dev/null has become a regular file.

2️⃣ Common Permission denied errors

🔲 File read and write permissions

To read a file, the account needs read (r) permission; to change it or create a new one, it needs write (w) permission. secret.txt, with permissions set to 600, can be read and written only by its owner, root.

ls -l secret.txt
-rw------- 1 root root 16 Oct 29 00:29 secret.txt
runuser -u daemon -- cat secret.txt
cat: secret.txt: Permission denied

Reading the same file as another account, daemon, was refused right away. Creating a file inside a folder without write permission gives the same error: on the Debian 12 server, touch as a regular account was blocked in a lock folder whose permissions were set to 000.

touch ~/touchtest/lock/x.txt
touch: cannot touch '/home/user/touchtest/lock/x.txt': Permission denied

In the first column of ls -l, check whether r and w are present for the owner, the group, and other accounts, in that order, then add permissions only for the account that needs them with chmod, or change the owner with chown.

🔲 Folder traverse permission

Even if the file permissions are right, you cannot reach a file when a folder in the middle of the path lacks the x permission. On a folder, x is the permission to pass through it and go inside, and r is the permission to read the list of names inside.

web/ ── drw-r--r-- · r yes · x no → blocked here
css/ ── name visible, permissions · size ?
style.css ── not reachable
index.html ── name visible, permissions · size ?
ls -ld web web/css
drw-r--r-- 3 root root 35 Oct 29 00:29 web
drw-r--r-- 2 root root 23 Oct 29 00:29 web/css
runuser -u daemon -- ls -l web
ls: cannot access 'web/css': Permission denied
ls: cannot access 'web/index.html': Permission denied
total 0
d????????? ? ? ? ?            ? css
-????????? ? ? ? ?            ? index.html

The web folder has only r, so daemon could read the names inside, css and index.html, but without x their permissions and sizes were left as question marks. Conversely, the site folder, which has x but no r, blocked the listing, while a file whose name was already known could be read.

ls -ld site
drwx--x--x 2 root root 24 Oct 29 00:29 site
runuser -u daemon -- ls site
ls: cannot open directory 'site': Permission denied
runuser -u daemon -- cat site/index.html
<h1>index</h1>

If the path is long, use ls -ld to check each folder for x starting from the top, and add to the blocked folder only the x the account needs to pass through.

🔲 Execute permission

To run a script as ./file name, the file needs the x permission. deploy.sh, with permissions 644, was refused.

ls -l deploy.sh
-rw-r--r-- 1 root root 8 Oct 29 00:29 deploy.sh
./deploy.sh
bash: line 1: ./deploy.sh: Permission denied

After chmod u+x added x for the owner, the first column changed to [-rwxr--r--].

chmod u+x deploy.sh
ls -l deploy.sh
-rwxr--r-- 1 root root 8 Oct 29 00:29 deploy.sh

If running is refused even with the x permission, check whether the file system holding that file is mounted with noexec.

🔲 Reading root-only information

A regular account cannot read information the system keeps for root, such as processes started by root or other accounts' password information. On the Debian 12 server, opening the fd folder of process 1 as a regular account gave a permission error.

ls /proc/1/fd
ls: cannot open directory '/proc/1/fd': Permission denied
chage -l daemon
chage: Permission denied.

Another account's password expiry information was blocked for the same reason; /etc/shadow, which holds it, is a file kept unreadable to regular users. For errors like these, do not widen the permissions; run the command again with sudo or as root.

🔲 When > is blocked even with sudo

sudo runs only the command written after it as root, while opening a file for redirection (>) is handled by the current account's shell before the command runs. So if you redirect the output of sudo echo to a file only root can write, the error line starts with the shell name, in the form [bash: file path: Permission denied].

sudo echo x > /root/test.txt

To do the redirection as root too, wrap the whole line in sh -c so the shell itself runs with sudo; the official sudo manual also gives an example of running inside sh -c so the redirection works.

sudo sh -c 'echo x > /root/test.txt'

tee takes standard input and writes it directly to the files you give it, so when you run tee with sudo, the file is opened by tee with root privileges. tee also prints what it receives to the screen once more.

echo x | sudo tee /root/test.txt

🔲 SSH login refused

If [account@server address:] comes before Permission denied and an authentication method such as publickey is in parentheses, the login was refused at the authentication step, and the place to check is different from file permissions. On the server, sshd has StrictModes set to the default yes, so before accepting a login it checks the permissions and owner of that account's home folder and files. If any one of the home folder, the ~/.ssh folder, and ~/.ssh/authorized_keys is writable by another account, sshd does not use that key file, so check with ls -ld that none of the three gives w permission to other accounts.

⌨️ Permission denied simulator

The simulator below starts as the root account, and with runuser you can become another account, daemon, and see for yourself the output when file reads, folder traversal, and execute permission are blocked.

Permission denied simulatorcoreutils 8.32
[root@server1 work]#
Runs only in your browser. It starts as the root account; put cat or ls after runuser -u daemon -- to see the output as another account, daemon.

3️⃣ Rare Permission denied errors

If you are refused even though the permission bits are right, something outside the permission bits blocked it, such as an SELinux policy or a noexec mount. If execution is refused even as root, check whether the file has no x bit at all.

On a server with SELinux enabled, Permission denied appears when an SELinux policy blocks the action even if the permission bits are right, so in that case check SELinux's denial records first. On servers running the audit daemon, denials are recorded in /var/log/audit/audit.log as [avc: denied], together with the blocked action, the command name (comm), and the target name (name).

Check whether SELinux is enabled with getenforce, then run ausearch as root to see today's denials.

getenforce
ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts today

rsync daemon transfers that failed with [Permission denied (13)] were also a case of SELinux blocking access to the module path.

On a file system mounted with noexec, files cannot be run directly, so even with x shown in ls -l, they are refused with [bash: script path: Permission denied]. Give the folder to findmnt -T to see where it is mounted and with which options; if the options include noexec, this is your case.

findmnt -T /tmp -o TARGET,OPTIONS

root bypasses most permission checks, but execution is allowed only when at least one of the owner, the group, or other accounts has x. That is why a script with no x at all is refused even when root runs it with ./.

Running deploy.sh, whose first column was [-rw-r--r-- 1 root root], with ./ as root returned [bash: line 1: ./deploy.sh: Permission denied].

🔲 When /dev/null has become a regular file

If the lines below appear one after another before the shell prompt right after you log in over SSH as a regular account, first check whether /dev/null, the character device every account uses to discard output, has turned into a regular file owned by root. The number of lines varies by server with the number of profile scripts read at login, and on the same server the error did not appear after switching to root.

-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
...
ls -l /dev/null
-rw-r--r-- 1 root root 55 Jan 10 09:00 /dev/null
stat -c %F /dev/null
regular file

The first column was [-rw-r--r--] and the size field showed 55: error text discarded by other commands had piled up in the file. If a cleanup command line containing the pattern below runs as root, rm deletes the device file, and the 2>/dev/null redirection of the next command creates a new regular file owned by root under the same name.

rm -f /dev/null 2>/dev/null

Run the line below as root. Creating the new device under a neighboring name and then overwriting with mv leaves no moment when the name is missing, so no other redirection gets a gap to create a regular file again between deleting and creating.

mknod -m 666 /dev/null.new c 1 3 && mv -f /dev/null.new /dev/null && ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Jan 10 09:05 /dev/null
stat -c %F /dev/null
character special file

The [c 1 3] in mknod is the number of /dev/null in the kernel's device number list. After the repair, echo x > /dev/null as a regular account also finished without errors. A reboot can also bring it back, but the one line above, which does not stop the server, is faster.

CheckBefore the fixAfter the fix
ls -l first column-rw-r--r--crw-rw-rw-
ls -l size field551, 3
stat -c %Fregular filecharacter special file
Writing as a regular accountPermission deniedNo error

Send output you want to discard only as far as >/dev/null or 2>/dev/null, and unless you are repairing it, never put /dev/null as the target of rm or mv.

🔢 FAQ & Recommended Content

Writing to a file system mounted read-only gives [Read-only file system], which is a different error (EROFS) from Permission denied. In that case, check what options the file system is mounted with before looking at permissions.

Opening read, write, and execute to every account makes that Permission denied go away, but other accounts can then change the file too. Adding permissions only for the account that needs them, or changing the owner, keeps the scope narrow.

Widening the permissions alone makes Permission denied go away, but /dev/null stays a regular file, so discarded output keeps piling up in it. It is repaired as a device only when stat reports character special file again.

ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.

Leave a Reply

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

Prove your humanity: 7   +   9   =