zsh: Permission Denied β How to Fix It on macOS and Linux
zsh: permission denied: ./script.sh
Youβre trying to run a file that doesnβt have execute permission.
Fix 1: Add Execute Permission
chmod +x ./script.sh
./script.sh
Thatβs it for 90% of cases. The file exists but isnβt marked as executable.
Fix 2: Run With the Interpreter Directly
If you canβt change permissions (read-only filesystem, etc.):
bash ./script.sh
python3 ./script.py
node ./app.js
This bypasses the execute permission check because youβre running bash/python3/node (which IS executable), and passing the file as an argument.
Fix 3: Downloaded Script from the Internet
macOS quarantines downloaded files. Even with chmod +x, you might get blocked.
# Remove quarantine attribute
xattr -d com.apple.quarantine ./script.sh
# Then make executable
chmod +x ./script.sh
Fix 4: Trying to Run a Directory
# β This is a directory, not a file
./my-project
# β
You probably meant
cd ./my-project
Fix 5: Wrong Shebang Line
If the script has a shebang (#!) pointing to a non-existent interpreter:
#!/usr/local/bin/python # β Python might not be here
#!/usr/bin/env python3 # β
Portable β finds python3 in PATH
#!/usr/bin/env bash # β
Portable β finds bash in PATH
Quick Diagnosis
# Check current permissions
ls -la ./script.sh
# -rw-r--r-- = no execute (missing x)
# -rwxr-xr-x = has execute
# Check file type
file ./script.sh
Related permission errors
- Linux: Permission Denied When Running Script
- Docker: Permission Denied
- npm EACCES: Permission Denied
- GitHub Actions: Permission Denied
- Git: Permission Denied (publickey)
Related resources
Related: Bash Cheat Sheet