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.
$ ls -l thefile && id $ 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.
$ ls -l script.sh $ 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.
$ namei -l /full/path/to/file $ 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.
$ ls -ld /the/directory $ 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.
$ mount | grep " / " && dmesg | tail -20 $ 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.
$ df -h . && quota -s 2>/dev/null $ See the dedicated page on "No space left on device". How to stop it happening again
- Never solve this with chmod 777. It works by removing all protection, and on a shared or public machine it is an open door.
- The standard recipe for a directory tree: 755 for directories, 644 for files. Apply it correctly with find . -type d -exec chmod 755 {} + and find . -type f -exec chmod 644 {} +.
- When a service cannot write its own files, fix ownership rather than permissions: sudo chown -R serviceuser:servicegroup /path.
- Learn to read ls -l fluently. Most permission incidents are diagnosed there before any command is run.
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
Change file permissions with numeric (755, 644) and symbolic (u+x) modes — clearly explained.
chownAssign files to users and groups — the other half of Linux permissions.
sudo & suTemporary privilege, audited — and why sudo won everywhere.
lsList 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
Give a script permission to run, and understand why it needs it.
Set a file to permission 755Understand what chmod 755 means and when it is appropriate.
Set a file to permission 644Learn what chmod 644 means and why it is common for ordinary files.
Run a script in LinuxRun Bash and executable scripts correctly using an interpreter, execute permissions and a shebang.
Other errors
SSH rejected your login because no key you offered was accepted by the server.
bash: command: command not foundThe shell searched every directory in your PATH and found no executable with that name.
No such file or directoryThe path you gave does not resolve — but often the missing part is not the one you think.
No space left on deviceA filesystem is full — confirm which one, and whether you ran out of bytes or inodes.