ZSH: permission denied
zsh: permission denied: happens when Zsh tries to execute a file without the executable (+x) permission bit, executes a shell config file like ~/.zshrc directly instead of sourcing it, or writes to a file owned by root rather than your user account.
1. Running a Script Without Execute Permission
When running a local shell script or CLI binary (e.g. ./deploy.sh), missing execute permission triggers zsh: permission denied: ./deploy.sh. Grant execute permission to your user or pass the script directly to zsh:
chmod +x ./deploy.sh
./deploy.sh
# Or invoke Zsh without modifying file mode bits
zsh ./deploy.sh
2. Reloading vs. Executing .zshrc (and Fixing Read/Write Permissions)
Shell config files like ~/.zshrc are configuration scripts, not standalone executables. Running ~/.zshrc directly fails with zsh: permission denied: /Users/username/.zshrc. Use source instead:
source ~/.zshrc
If an editor cannot save ~/.zshrc, add owner read and write permissions (u+rw):
chmod u+rw ~/.zshrc
3. Fixing Root-Owned Files and Directories
If changing permissions returns Operation not permitted or ls -l shows root as the owner:
ls -l ~/.zshrc
# -rw-r--r-- 1 root staff 567 Aug 28 10:30 /Users/username/.zshrc
Reassign ownership back to your user account with chown:
# macOS (primary group: staff)
sudo chown "$USER":staff ~/.zshrc
# Linux (primary group matches username)
sudo chown "$USER":"$USER" ~/.zshrc
Once ownership matches your account, standard edits and chmod changes work normally without sudo.
Sources
- GNU Coreutils Manual:
chmodinvocation - GNU Coreutils Manual:
chowninvocation
