If a script says zsh: permission denied in Mac Terminal, run chmod +x script.sh and try again. If the message says “Operation not permitted” instead, something other than the file’s permission bits is blocking you, such as macOS privacy protection, System Integrity Protection (SIP) or a locked file, and chmod and sudo won’t lift those.
New accounts on macOS use zsh, which is why the errors start with zsh:. I observed the command output and System Settings wording below on macOS 26.6. In each version from macOS 13 Ventura through macOS 27 Golden Gate, Apple’s Privacy & Security guide gives the same System Settings path and lists a Full Disk Access option.
Table of Contents
Match your “permission denied” or “operation not permitted” error to the fix
| What you see | Cause | Fix |
|---|---|---|
zsh: permission denied: ./script.sh |
The script has no execute bit | chmod +x script.sh |
zsh: permission denied: /Users/you/Projects |
You typed only a folder path, so zsh tried to run it | cd into it, or open it in Finder |
cd: permission denied: folder or mkdir: /Library/mytools: Permission denied |
Another user (often root) owns it, or a folder on the path lacks the execute (search) bit | ls -ld the folder; chmod u+x if it is yours, otherwise sudo |
zsh: permission denied: /etc/hosts after sudo echo "..." >> /etc/hosts |
Your shell opens the file for the redirect before sudo runs | echo "..." | sudo tee -a /etc/hosts |
chmod: Unable to change file mode on /etc/hosts: Operation not permitted |
Only a file’s owner or root can change its mode | sudo chmod or sudo chown |
ls: /Users/you/Library/Safari: Operation not permitted |
macOS privacy protection (TCC) blocks your terminal app | Files & Folders or Full Disk Access, then Quit & Reopen |
touch: /usr/bin/x: Operation not permitted, even with sudo |
SIP protects /usr/bin |
Nothing to fix; use /usr/local or your home folder |
rm: notes.txt: Operation not permitted on your own file |
ls -lO shows uchg: the file is locked |
chflags nouchg notes.txt |
| An alert: “Apple could not verify … is free of malware” | The download is quarantined and not notarized | Open Anyway, or xattr -d com.apple.quarantine file |
git@github.com: Permission denied (publickey). |
The SSH server rejected your key, not a Mac file permission | Add your public key to the account; chmod 600 a key ssh calls “too open” |
If nothing matches, ls -ldO@e path prints the owner, mode, flags, extended attributes and ACLs of a file or folder in one listing.
Fix “zsh: permission denied” when you run a script
A file runs as a program only if its mode has an x. Files you download in a browser arrive without one, and so do files you create yourself:
$ ls -l backup.sh
-rw-r--r-- 1 you staff 29 Oct 1 10:38 backup.sh
$ chmod +x backup.sh
$ ls -l backup.sh
-rwxr-xr-x 1 you staff 29 Oct 1 10:38 backup.sh
To run a file once without changing it, pass it to its interpreter, such as zsh backup.sh or bash backup.sh. Folders need x too, so they can be entered.
Fix “permission denied” on files that root owns (sudo and chown)
ls -l shows the owner and group before the size. /etc/hosts belongs to root with mode -rw-r--r--, so only root can write to it. sudo runs one command as root. If an earlier sudo run left your files owned by root, take them back (only root can change an owner):
sudo chown -R "$USER":staff ~/Projects/site
Check the path first, because -R changes everything under it. Redirects trip people up: sudo echo "..." >> /etc/hosts still fails, because your shell opens the file before sudo starts. Let tee open it instead:
echo "127.0.0.1 example.test" | sudo tee -a /etc/hosts
Fix “Operation not permitted” in Terminal with Full Disk Access
macOS’s privacy protection, TCC (Transparency, Consent and Control), makes each app get your permission before it reads Desktop, Documents, Downloads, iCloud Drive or network volumes, and it keeps apps out of data like Mail, Messages and Safari unless you grant Full Disk Access. The permission is granted to the app you type in, not to your user account, so ls ~/Library/Safari fails even though you own the folder and its mode is drwxr-xr-x.
- Choose Apple menu → System Settings, then click Privacy & Security in the sidebar (scroll down if needed).
- For Desktop, Documents, Downloads or removable and network volumes, open Files & Folders (Apple’s macOS 13 and 14 guides spell it Files and Folders) and switch on the matching folder under your terminal app. For anything else, open Full Disk Access and turn on the terminal app; if it isn’t listed, click +, choose the app (Terminal is in Applications → Utilities) and click Open.
- macOS says the app won’t have access until it is quit. Click Quit & Reopen, then run the command again.
Grant the app you type commands in: iTerm2 and the terminal inside VS Code need their own entries. sudo doesn’t bypass the check, because Apple’s developer support says processes running as root are subject to it too. Full Disk Access exposes all your data to everything you run in that app, so I’d switch it off again afterwards.
Apple’s macOS 27 release notes say other developers’ app data, including their containers, can be denied by default without a prompt and is managed in Privacy & Security. On macOS 12 and earlier, the pane is System Preferences → Security & Privacy → Privacy.
Why sudo can’t fix “Operation not permitted” (SIP and locked files)
System Integrity Protection limits what even root can change. Apple lists /System, /usr, /bin, /sbin, /var and the apps that come with macOS as protected; /usr/local stays open to installers. Protected files carry a restricted flag:
$ ls -lO /bin/ls
-rwxr-xr-x 1 root wheel restricted,compressed ... /bin/ls
$ csrutil status
System Integrity Protection status: enabled.
Apple’s developer documentation describes turning SIP off (csrutil disable, from Recovery) only as a temporary step. For a permission error I’d install into /usr/local or your home folder instead.
A locked file refuses changes even from its owner. ls -lO shows uchg in the flags column, and chflags nouchg notes.txt clears the flag.
Open a downloaded program that macOS blocked (quarantine)
Browsers tag downloads with a com.apple.quarantine attribute, and macOS asks for approval the first time you open downloaded software. If it can’t check the program for malware, you get an alert, not a permission error. Apple’s route for an app is Privacy & Security → Open Anyway, available for about an hour after the attempt. For a command-line tool, xattr lists a file’s attributes and can remove the tag:
xattr ./tool
xattr -d com.apple.quarantine ./tool
xattr -r -d com.apple.quarantine ~/Downloads/tool-folder
Do this only for software you trust. Apple warns that overriding these checks is the most common way a Mac gets infected with malware.
I tested only on macOS 26.6, so I haven’t confirmed the Quit & Reopen button or the Files & Folders labels on macOS 27; I also couldn’t run anything under sudo (it needs a password), so what sudo can’t do against SIP and privacy protection comes from Apple’s documentation, and I haven’t tried xattr -d or Open Anyway on a blocked command-line tool.