How to fix "Permission denied" on Linux
Diagnose and fix Permission denied errors: read the permission bits, correct ownership with chown, set the right mode with chmod, and know when sudo is the wrong answer.
Intermediate · about 7 min · Linux, macOS, WSL
"Permission denied" almost never means you need 777. It means the user running the command lacks read, write or execute on that path — or on a directory above it. Diagnose in that order and the fix is usually one command.
What this guide covers
- See who you are and who owns the file
- Read the permission string
- Check the whole path, not just the file
- Fix ownership when the file belongs to the wrong user
- Set sensible modes
- Script says Permission denied even after chmod +x
Common pitfalls covered
- chmod 777 hides the problem and opens the file to every user and service on the box — never on a server.
- Recursive chmod on a whole tree makes files executable that should not be; use …/… to target each separately.
- sudo on a file you will edit daily creates root-owned files that break your normal user later.
Questions answered
- Why do I get Permission denied even as root?
- What permissions should a web root have?
- chmod or chown — which do I need?
This is a limited preview. The full walkthrough, command syntax and copy-ready examples are available to signed-in users.