Troubleshooting “zsh: operation not permitted”


If you try to run a script from the Terminal in macOS, you may get an error that says zsh: operation not permitted.

As of this writing, the top Google search results for that all point to needing to grant the Terminal full disk access (either via System Preferences > Security & Privacy > Privacy > Full Disk Access or via MDM-delivered PPPC profile.

If that works for you, great!

But it could also be that there is an Apple quarantine extended attribute on your script. Now, of course, don’t take that extended attribute off if you don’t trust the script. If you do trust it, though, you can remove that extended attribute.

To see the extended attributes, run

xattr -l /PATH/TO/SCRIPTYOUCANTRUN.sh

If you see com.apple.quarantine in there, you can remove it by running

xattr -d com.apple.quarantine /PATH/TO/SCRIPTYOUCANTRUN.sh

The only other thing you may want to check is that your script is executable:

ls -l /PATH/TO/SCRIPTYOUCANTRUN.sh

There should be some x‘s in there (read man chmod for more details).

If it’s not, you can add the executable flag to it:

chmod +x /PATH/TO/SCRIPTYOUCANTRUN.sh


25 responses to “Troubleshooting “zsh: operation not permitted””

  1. Awesome, I don’t know why the flag got flipped on my script, but I was left scratching my head; not least since I used the script 5 minutes before…

  2. Thank you. I’ve been searching everywhere for two days, and your advice is very very very helpful. I’m using all my *.sh files in Tomcat 9 shell script in the folder bin. Thanks again.

Leave a Reply to Teus Cancel reply

Your email address will not be published. Required fields are marked *