Cause #1: Missing Execute Permission on the File or Script
This is the one I see most often. A client calls me because their backup script won't run. They try ./backup.sh and get bash: ./backup.sh: Permission denied. Nine times out of ten, the script isn't marked as executable. It's not a permissions conspiracy — the file just needs the execute bit set.
Here's the quick fix:
chmod +x backup.sh
./backup.sh
That adds execute permission for the owner, group, and everyone else. If you want to be more precise, you can do chmod u+x backup.sh for just the owner. But honestly, for a script you own, chmod +x is fine.
How do you check? Run ls -l backup.sh. If the first column looks like -rw-r--r--, there's no x — that's your problem. If it's -rwxr-xr-x, you're good.
I've also seen this with compiled binaries. Last month, a client downloaded a tool from GitHub, extracted it, and got 'Permission denied' when running it. Same fix — chmod +x on the binary. It's not rocket science, but it trips up even experienced folks when they're in a hurry.
One more thing: if you're using a desktop environment and double-clicking a script, the file manager might ask if you want to run it or just open it in a text editor. That's a separate setting, but the underlying issue is still the execute bit.
Cause #2: File Ownership Mismatch
You log in as your user, try to edit a config file, and get Permission denied even though the file looks readable. That's usually because the file belongs to another user or root. This happens all the time with files copied from a USB drive or extracted from a tarball created by someone else.
I had a client whose web developer uploaded files via FTP. The web server process (running as www-data) couldn't write to the files because they were owned by the FTP user. Classic.
The fix is to change ownership. If you have sudo access:
sudo chown yourusername:yourgroup /path/to/file
Or if it's a whole directory, use -R for recursive:
sudo chown -R yourusername:yourgroup /var/www/html
Check who owns a file with ls -l. The third and fourth columns show user and group. If they're not you, that's your problem.
Sometimes you just need to add yourself to a group. For example, if you get permission denied on a serial port like /dev/ttyUSB0, you might need to be in the dialout group. Run sudo usermod -aG dialout $USER and log out and back in. That's not ownership per se, but it's in the same family.
The key here: don't just chmod 777 everything and move on. That's a band-aid that can open security holes. Changing ownership is the right fix.
Cause #3: Filesystem Mounted Read-Only or with noexec
This one's sneaky because the file permissions look perfect, but you still get 'Permission denied'. I saw this with a client's external drive that was mounted read-only because the filesystem had errors. Another scenario: a server admin mounted a partition with the noexec option to prevent script execution. Then they tried to run a script from it and got permission denied even with execute bits set.
First, check if the filesystem is mounted read-only. Run mount or df -h. Look for ro in the options. If it's read-only, you need to remount it as read-write:
sudo mount -o remount,rw /mount/point
That often fixes it for the current session. But if the drive has filesystem errors, you might need to run fsck before you can remount it read-write. That's a bit deeper, but it's a real cause.
If the mount has noexec, you can either remount with exec:
sudo mount -o remount,exec /mount/point
Or you can copy the script to your home directory and run it from there. The second option is sometimes better if the noexec is intentional for security.
I had a client with a CI server that suddenly couldn't run build scripts. Turned out the admin had added noexec to /tmp to stop malware. The build scripts were in /tmp. Moving them to /var/lib/build and updating the path fixed it without weakening security.
Quick Reference Summary
| Symptom | Likely Cause | Fix |
|---|---|---|
| Permission denied when running a script or binary | Missing execute bit | chmod +x file |
| Permission denied editing a file you should have access to | Wrong ownership | sudo chown user:group file |
| Works on one machine, fails on another with same permissions | Filesystem mounted read-only or noexec | sudo mount -o remount,rw,exec /mount/point |