If you’re seeing “zsh: permission denied” when trying to run a script or command in the Mac Terminal, it usually means the file doesn’t have execute permissions, or macOS is blocking it for security reasons. This guide walks you through the quick fixes, from changing file permissions to clearing extended attributes, so you can get back to work.
What You’ll Need
- A Mac running macOS Catalina (10.15) or later, where zsh is the default shell.
- The full path to the file or command that’s giving the error.
- Administrator access if the file is in a system-protected location (you may need to use
sudo).
Step-by-Step
- Identify the file or command. Look at the error message. It usually says something like
zsh: permission denied: ./script.sh. Note the exact path and name. - Check the current permissions. In Terminal, run
ls -l /path/to/file. You’ll see a string like-rw-r--r--at the start. The first character is the file type (-for regular file,dfor directory). The next nine characters are permissions: three for the owner, three for the group, three for others. Thexcharacter means execute. If there’s noxin the owner’s group (e.g.,-rw-r--r--), the file isn’t executable. - Make the file executable. Run
chmod +x /path/to/file. This adds execute permission for the owner, group, and others. If you only want the owner to execute it, usechmod u+x /path/to/file. - Try running the command again. Use
/path/to/fileor./fileif you’re in the same directory. It should now run, unless there’s another issue (see troubleshooting below). - If it still fails, check for extended attributes. macOS may quarantine downloaded files. Run
xattr -l /path/to/fileto list attributes. If you seecom.apple.quarantine, remove it withxattr -d com.apple.quarantine /path/to/file. - If the file is in a protected location (like
/usr/binor/System), you may need to usesudo chmod +x /path/to/file. Enter your password when prompted. Be careful—only do this for files you trust. - If you’re trying to run a command that’s not a file (like
mycommand), it might be that the command isn’t in your PATH. Check withwhich mycommand. If it’s not found, you may need to install it or add its directory to your PATH in~/.zshrc. - Restart Terminal or run
source ~/.zshrcafter making PATH changes to apply them.
Common Mistakes
- Using
chmod 777unnecessarily. This gives everyone full permissions, which is a security risk. Usechmod +xorchmod 755instead. - Forgetting to include
./for files in the current directory. zsh won’t run a file just by typing its name unless it’s in your PATH. Use./script.sh. - Editing the wrong file. Make sure you’re changing permissions on the actual script, not a symlink or a copy.
- Ignoring the quarantine attribute. Even after
chmod +x, a downloaded file may still be blocked by Gatekeeper. Always checkxattrif the error persists. - Using
sudoon a file you don’t own. This can cause permission issues later. Try to change ownership withsudo chown $(whoami) /path/to/fileif needed.
Tips
- Use
chmod 755for scripts you want others to read and execute, but only you can write. This is a common, safe permission set. - Check the shebang line. For shell scripts, the first line should be
#!/bin/zshor#!/bin/bash. If it’s missing or wrong, the script may fail with a permission error even if permissions are correct. - If you’re writing a script, save it with Unix line endings. Windows-style CRLF can cause weird errors. Use a text editor that supports Unix line endings.
- Add a directory to your PATH if you have many scripts you want to run from anywhere. In
~/.zshrc, addexport PATH="$HOME/bin:$PATH"and put your scripts in~/bin. - Use
file /path/to/fileto see what type of file it is. If it’s a binary, you may need to check its architecture (e.g., Intel vs. Apple Silicon).
Troubleshooting
- Still getting “permission denied” after
chmod +x? Check if the file is on a filesystem that doesn’t support Unix permissions, like a FAT32 drive. Copy it to your Mac’s internal drive and try again. - Error says “cannot execute binary file”? This means the file isn’t a valid executable for your Mac’s architecture. For example, an x86 binary won’t run on an ARM Mac without Rosetta 2. Install Rosetta 2 with
softwareupdate --install-rosettaor get an ARM version. - Script runs but does nothing? Check for syntax errors by running
zsh -n /path/to/fileto parse without executing. - Permission denied on a directory? You need execute permission on the directory to enter it. Use
chmod +x /path/to/directory. - If you’re using a package manager like Homebrew and getting permission errors, you may have installed it with the wrong ownership. Run
sudo chown -R $(whoami) /opt/homebrew(or/usr/localfor Intel Macs) to fix. - Check if System Integrity Protection (SIP) is blocking you. If you’re trying to modify files in
/Systemor/usr, SIP may prevent it. You can’t disable SIP easily, and it’s not recommended. Instead, use your home directory or/usr/local.
Frequently Asked Questions
Why does zsh say “permission denied” even though I own the file?
Ownership doesn’t guarantee execute permission. The file may have read/write but not execute. Use chmod +x to add it.
How do I permanently allow a downloaded app to run?
Right-click the app and select “Open” from the context menu, then click “Open” in the dialog. This adds a one-time exception. For scripts, remove the quarantine attribute as shown above.
What’s the difference between chmod +x and chmod 755?
chmod +x adds execute permission to the existing permissions. chmod 755 sets the owner to read/write/execute, and group and others to read/execute. The latter is more explicit.
Can I run a script without making it executable?
Yes, you can run it with zsh /path/to/file or bash /path/to/file (depending on the shebang). This bypasses the need for execute permission.
Why does my script work in Terminal but not when double-clicked?
Double-clicking a script may open it in a text editor instead of executing it. You can set the default app to Terminal in the Get Info panel, or create an Automator app to run it.
What does “operation not permitted” mean in zsh?
This often happens when a process lacks the necessary macOS privacy permissions, like accessing files in Desktop, Documents, or Downloads. Go to System Settings → Privacy & Security → Files and Folders, and grant Terminal access.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Custom Alphanumeric Passcode iPhone: How to Set
- Quick Look Not Working on Mac? Fixes That Work
- How to See Deleted WhatsApp Messages on iPhone
- HomePod Software Update: How to Install
- How to Shuffle Photos in Slideshow on iPhone
- QUIC Protocol Error in Windows 10: Fixes