Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Permission denied

'Permission denied' on Linux: owners, modes and the parent directory

The user the process runs as lacks the read, write or execute right on the file or a directory on its path.

Linux

What it means

Every file has an owner, a group and a mode (rwx for each). To open /srv/app/data/file you also need execute (x) on every directory on the path. Services often run as their own user, so a file that works for root fails for the service.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. Wrong owner after copying files as root

Check:

ls -l /path/to/file
namei -l /path/to/file
ps -o user= -p <pid>

Fix: chown the files to the service user (chown -R app:app /srv/app/data).

2. A directory on the path lacks x for that user

Check:

namei -l /path/to/file

Fix: Add execute on the directory (chmod o+x or g+x), not 777 on everything.

3. Running a script without the execute bit, or from a noexec mount

Check:

ls -l script.sh; findmnt -no OPTIONS --target script.sh

Fix: chmod +x script.sh, or run it with bash script.sh; move it off a noexec mount.

The long version, step by step: sudo echo >> /etc/hosts: Permission denied. Why sudo didn't help

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors