How to Fix chmod Permission Denied Error
In this tutorial, you'll learn about How to Fix chmod Permission Denied Error. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
The Problem
You run chmod on a file and get:
chmod: changing permissions of 'script.sh': Operation not permitted
Or:
chmod: cannot access 'protected-file': Permission denied
Only the file owner or root can change permissions on a file. If you are not the owner and do not have sudo access, the operation is blocked.
Quick Fix
Step 1: Check the current owner
ls -la script.sh
Expected output:
-rwxr-xr-x 1 root root 1024 Mar 15 10:30 script.sh
If the owner is root, you need sudo.
Step 2: Use sudo
sudo chmod +x script.sh
Enter your password when prompted.
Step 3: Verify the change
ls -la script.sh
Expected:
-rwxr-xr-x 1 root root 1024 Mar 15 10:30 script.sh
The x in the permission string means execute is now set.
Step 4: If sudo fails
If you cannot use sudo, request ownership from the file owner or an admin:
# Admin can change ownership
sudo chown your-username:your-group script.sh
Then you can run chmod without sudo.
Alternative Solutions
If the filesystem is mounted with noexec, even chmod +x will not allow execution:
mount | grep noexec
Remount with exec permission:
sudo mount -o remount,exec /path/to/mount
Prevention
- Always check file ownership before running
chmod. - Avoid running
chmodon system files without understanding the implications. - Use
sudo chownto take ownership of files you need to manage. - Check filesystem mount options if execute permission keeps reverting.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro