How to fix "zsh: permission denied" on a Mac

Tested: we reproduced this error and confirmed the fix on zsh 5.9 on Ubuntu 24.04 (the same shell macOS uses; macOS-only causes are marked), November 29, 2026.

zsh found the file you asked it to run, but the file isn’t marked as executable (or it’s a folder). For a script, add execute permission and run it again:

chmod +x script.sh
./script.sh

Or run it through its interpreter without changing permissions: bash script.sh, sh script.sh or python3 script.py.

We reproduced each cause below in zsh 5.9, the same shell macOS uses. The two causes that only happen on a Mac are marked as researched.

What the message tells you

In Terminal it looks like this, with the path that failed after the colon:

zsh: permission denied: ./script.sh

In scripts the line number is added (zsh:1: permission denied: ./s.sh). In our tests the exit status was 126, which means “found but couldn’t run”. “Command not found” is status 127 and a different problem.

Causes and fixes

What you ran Why zsh refused Fix
A script you downloaded or wrote (./install.sh) The file has no execute permission (-rw-r--r--) chmod +x install.sh, or bash install.sh
~/.zshrc, ~/.zprofile or another settings file You ran the settings file as a command source ~/.zshrc
A folder name (./project or /usr/local) Folders can’t be run cd ./project
A command in a folder on your PATH That copy isn’t executable chmod +x on the file which -a <name> shows
echo ... > file or saving a file You don’t own the file or folder (often after sudo) sudo chown $(whoami) file
A script inside another user’s folder You can’t enter that folder Copy the script somewhere you own

A script without execute permission

This is the common one. ls -l shows the permissions:

-rw-r--r-- 1 you staff 21 Nov 29 22:41 s.sh

After chmod u+x s.sh it showed -rwxr--r-- and the script ran. u+x makes it executable for you only. +x makes it executable for everyone, which is fine for your own scripts.

Running .zshrc instead of loading it

Typing ~/.zshrc asks zsh to run the file as a program, and it isn’t one. In our test this printed zsh:1: permission denied: /tmp/zr/.zshrc. To apply changes from .zshrc in the window you have open, load it instead:

source ~/.zshrc

Don’t fix this with chmod +x ~/.zshrc. The file is meant to be read by zsh at startup, not run.

Typing a folder

Typing ./d or /tmp/zp/d where d is a folder gave zsh:1: permission denied: ./d. Use cd to move into it. If you want zsh to move into folders when you type just their name, setopt auto_cd in ~/.zshrc turns that on.

Writing to a file you don’t own

Redirecting output into a file owned by another user gave zsh:1: permission denied: /tmp/zp/s.sh with exit status 1. This often happens after editing a file with sudo, which makes root the owner. Check with ls -l and take ownership back:

sudo chown "$(whoami)" ~/.zshrc

When .zshrc itself was unreadable in our test, zsh started without it and printed no warning. If your settings seem to be ignored, check the owner of ~/.zshrc.

Similar errors that need a different fix

  • bad interpreter: /bin/bash^M: no such file or directory: the script has Windows line endings. We got this from a file saved with CRLF. Convert it with sed -i '' $'s/\r$//' script.sh on a Mac, or save it with LF line endings in your editor.
  • bad interpreter: /bin/nothere: the #! line names a program that doesn’t exist. Fix the first line (for example #!/usr/bin/env bash).
  • zsh: command not found: zsh couldn’t find the command at all. For Python, see zsh: command not found: python. For Homebrew, see brew command not found.
  • Operation not permitted (Mac only, researched): macOS privacy protection is blocking Terminal from a folder such as Desktop, Documents or Downloads, or from a protected system path. Grant Terminal access in System Settings > Privacy & Security > Full Disk Access (or Files and Folders), then reopen Terminal. chmod doesn’t help here.

When sudo is the wrong fix

sudo ./script.sh doesn’t fix a missing execute bit. Root also needs the file to be executable. Running installers or brew with sudo can leave root-owned files in your home folder or Homebrew’s folders, which then cause permission denied for your normal user. If that’s already happened with Homebrew, brew doctor prints the exact chown command to fix it. See what brew doctor’s warnings mean.

FAQ

How do I resolve zsh: permission denied?

Look at the path after the colon. If it's a script, run chmod +x on it and try again, or run it with bash script.sh. If it's ~/.zshrc or another settings file, you meant source ~/.zshrc. If it's a folder, you typed a folder name as a command: use cd first.

How do I fix permission denied on a Mac?

For a script, add execute permission with chmod u+x file. For a file you're trying to write, check the owner with ls -l; if it's root, you probably created it with sudo, and sudo chown $(whoami) file gives it back. "Operation not permitted" is a different, macOS privacy error that needs Full Disk Access instead.

Should I use sudo to fix permission denied?

Usually not. A missing execute bit isn't fixed by sudo, and running scripts or Homebrew as root can leave files that only root can change, which causes more permission errors later. Use sudo only for system files you know need it.

What is zsh on a Mac?

zsh (Z shell) is the program that reads the commands you type in Terminal. Apple says it has been the default shell for newly created user accounts since macOS 10.15 Catalina, replacing bash. Error messages that start with zsh: come from it.