Error message

Permission denied

The path resolves fine — the system simply will not let you do that with it.

Quick diagnosis

Start here. This one command usually tells you which of the causes below you are dealing with:

$ ls -la thefile && id && namei -l "$(realpath thefile)"

Shows the file's permissions, who you currently are, and — the part everyone forgets — the permissions of every directory along the path.

Causes, ordered by how often they are the culprit

1 The file belongs to another user

Permissions are checked against a single audience: owner if the UIDs match, otherwise group, otherwise "others". Files created by root or by a service are frequently not yours.

Check
$ ls -l thefile && id
Fix
$ sudo chown youruser:yourgroup thefile

On a server, think before taking ownership of files a service needs. Often the correct fix is the opposite: give them to the service user.

2 You are trying to run a file that is not executable

Executability is a permission bit, not a file extension. A freshly downloaded or copied .sh has no execute bit.

Check
$ ls -l script.sh
Fix
$ chmod +x script.sh

Or bypass it entirely by invoking the interpreter: bash script.sh.

3 A directory in the path is not traversable

To reach a file you need execute permission on every directory above it. A perfectly readable file inside a 750 directory you have no access to is unreachable — and the error only mentions the file.

Check
$ namei -l /full/path/to/file
Fix
$ sudo chmod o+x /the/blocking/directory

namei -l prints the permissions of each path component in order. The first line you cannot pass is your culprit.

4 Writing to a system location without sudo

Everything under /etc, /usr, /var and / itself belongs to root by design.

Check
$ ls -ld /the/directory
Fix
$ sudo the-command

Careful: sudo cmd > /etc/file still fails, because your shell performs the redirection. Use: echo data | sudo tee /etc/file.

5 The filesystem is mounted read-only

After a disk error Linux may remount a filesystem read-only to protect it. Then nothing can be written, no matter who you are — including root.

Check
$ mount | grep " / " && dmesg | tail -20
Fix
$ sudo mount -o remount,rw /

This is a symptom, not the problem. Check dmesg for disk errors before assuming it is fixed.

6 The disk is full or the quota is exhausted

Some tools report "Permission denied" when what actually failed was the write itself.

Check
$ df -h . && quota -s 2>/dev/null
Fix
$ See the dedicated page on "No space left on device".

How to stop it happening again

Frequently asked questions

Why not just use chmod 777?

Because it grants every user on the system full write access. On a server that is a security hole, and many services (SSH, web servers) refuse to use files that are too permissive.

Why does sudo command > /etc/file still fail?

The redirection is performed by your unprivileged shell before sudo runs. Move the write into the privileged process: echo data | sudo tee /etc/file.

I own the file and it still says permission denied

Check the directories above it with namei -l. Owning a file is useless if you cannot traverse the path to reach it.

What is the difference between this and "Operation not permitted"?

"Permission denied" (EACCES) is a normal permission check. "Operation not permitted" (EPERM) means the operation itself is reserved — typically requiring root, like changing a file's owner.

Commands involved

chmod

Change file permissions with numeric (755, 644) and symbolic (u+x) modes — clearly explained.

chown

Assign files to users and groups — the other half of Linux permissions.

sudo & su

Temporary privilege, audited — and why sudo won everywhere.

ls

List the contents of a directory, with options for hidden files, long format, sorting and more.

Concepts behind this error: File permissions · Root · umask

How to do it properly

Make a script executable

Give a script permission to run, and understand why it needs it.

Set a file to permission 755

Understand what chmod 755 means and when it is appropriate.

Set a file to permission 644

Learn what chmod 644 means and why it is common for ordinary files.

Run a script in Linux

Run Bash and executable scripts correctly using an interpreter, execute permissions and a shebang.

Other errors

Permission denied (publickey)

SSH rejected your login because no key you offered was accepted by the server.

bash: command: command not found

The shell searched every directory in your PATH and found no executable with that name.

No such file or directory

The path you gave does not resolve — but often the missing part is not the one you think.

No space left on device

A filesystem is full — confirm which one, and whether you ran out of bytes or inodes.