Permission denied
The Permission denied error in Linux means your user lacks the required access rights to read, write, or execute a file or directory. This guide shows you how to diagnose and fix it using standard permission commands.
What It Means
Linux uses a permission system with three tiers: owner, group, and others. Each tier has read (r), write (w), and execute (x) flags. When you try an operation your user doesn’t have permission for, the kernel blocks it and prints Permission denied.
Why It Happens
- The file doesn’t have the execute bit set for a script or binary.
- You’re trying to write to a directory owned by root (like
/etc/or/usr/). - The file is owned by another user and doesn’t grant you access.
- A parent directory lacks execute permission, blocking access to files inside it.
- The filesystem is mounted with restrictive options (e.g.,
noexec,read-only).
How to Fix It
1. Check current permissions
ls -l filenameThe output shows permissions as a 10-character string like -rwxr-xr--. The first character is the file type, then three groups of three: owner, group, others.
2. Add execute permission for a script
chmod +x script.sh
./script.shchmod +x adds execute for all tiers. Use chmod u+x for only the owner.
3. Run a command as root with sudo
sudo apt update
sudo systemctl restart nginxOnly use sudo when you trust the command — it runs with full root privileges.
4. Change file ownership
sudo chown youruser:yourgroup filenameReplace youruser with your username. Use chown -R to change ownership recursively on directories.
5. Fix parent directory permissions
If you can’t cd into a directory, its execute bit may be missing:
chmod +x /path/to/dir6. Check filesystem mount options
mount | grep /mountpointIf you see noexec or ro, remount with the right options:
sudo mount -o remount,exec /mountpointBuilt by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro