How to Fix 'Permission Denied' Error in Linux
DodaTech
1 min read
In this tutorial, you'll learn about How to Fix 'Permission Denied' Error in Linux. We cover key concepts, practical examples, and best practices.
The Problem
You try to run a script, write to a file, or access a directory and get:
bash: ./script.sh: Permission denied
or
touch: cannot touch '/etc/config': Permission denied
Quick Fix
Make a file executable
chmod +x script.sh
./script.sh
Make a file readable/writable for yourself
chmod u+rw file.txt
Fix directory permissions (readable + executable)
chmod 755 /path/to/dir # rwxr-xr-x
Change file ownership
sudo chown $USER:$USER /path/to/file
Run a single command as root
sudo apt update
Permission Reference
| chmod | Owner | Group | Others |
|---|---|---|---|
chmod 644 file |
rw- | r-- | r-- |
chmod 755 file |
rwx | r-x | r-x |
chmod 600 file |
rw- | --- | --- |
chmod 700 file |
rwx | --- | --- |
chmod 777 file |
rwx | rwx | rwx |
⚠️ Never use 777 on production — it allows anyone to modify the file.
Recursive Fix
Fix an entire directory tree:
chmod -R 755 /var/www/project
chown -R www-data:www-data /var/www/project
← Previous
Website Carbon Footprint Reduction Fix
Next →
Fix pgAdmin Backup & Restore – Incomplete or Corrupt Dumps
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro