Skip to content

How to Fix Linux Permission Denied (chmod) Error

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Linux Permission Denied (chmod) Error. We cover key concepts, practical examples, and best practices.

You try to run a script or access a file and get Permission denied — the file lacks the correct read, write, or execute permissions for your user.

The Problem

bash: ./script.sh: Permission denied

Or:

touch: cannot touch '/etc/config.ini': Permission denied

Step-by-Step Fix

Step 1: Check current permissions

ls -la script.sh

Expected:

-rw-r--r--  1 user user 1024 Jun 24 10:00 script.sh

Missing x in the first column means execute is not set.

Step 2: Add execute permission

chmod +x script.sh

Verify:

ls -la script.sh

Expected:

-rwxr-xr-x  1 user user 1024 Jun 24 10:00 script.sh

Step 3: Fix read/write permissions

# Add read and write for owner
chmod u+rw file.txt

# Add read for group and others
chmod go+r file.txt

# Full permissions for owner, read/execute for others
chmod 755 script.sh

Step 4: Change file ownership

If you need to access a file owned by another user:

sudo chown $(whoami):$(whoami) file.txt

Step 5: Fix directory permissions

For directories, execute (x) is needed to enter:

chmod +x /path/to/directory
chmod -R +x /path/to/directory  # recursive

Step 6: Use sudo when necessary

For system files owned by root:

sudo nano /etc/hosts

Prevention Tips

  • Set execute permission when creating scripts: chmod +x script.sh
  • Use umask to control default permissions (e.g., umask 022)
  • Never use chmod 777 for security reasons
  • Use sudo only when necessary
  • Check ownership with ls -la before troubleshooting

Common Mistakes with permission denied

  1. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  2. Misunderstanding that String is [Char] with poor performance for large text operations
  3. Using foldl instead of foldl' causing stack overflow on large lists

These mistakes appear frequently in real-world LINUX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What does chmod 755 mean?

chmod 755 sets rwx (7) for owner, rx (5) for group, and rx (5) for others. This is the standard for executable files and directories. chmod 644 (rw-r--r--) is standard for regular files.

Why do I get permission denied even as root with sudo?

If SELinux or AppArmor is enforcing, even root can be denied. Check with ls -Z for SELinux context, and try sudo setenforce 0 temporarily to test. If it works, create a proper SELinux policy.

How do I fix permission denied for a directory I created?

Check the parent directory permissions. You need execute (x) on all parent directories to reach the file. For example, if /home/user is not executable by others, subdirectories are inaccessible.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro