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””
Thank you!
You saved me with this. I literally love you right now
That worked for me, thank you!
Excellent. This was most helpful, thanks a lot.
Great, I was dancing with chmod to no avail.
Thank you!
Thank you!
Thank you for that. It seems a new problem because my script that written years ago still runs.
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…
You saved me. Indebted
Thanks! Sometimes Apple makes life difficult for devs.
i am seriously thankful of you!
Thank you so much for the tip!
Very, very helpful. Thank you!
thanks bro saved my day
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.
Hey thanks for this it was great!
In my case it was a BBEdit sandboxing issue: https://www.barebones.com/support/bbedit/quarantine.html
But I would not have solved that if it wasn’t for this page. Thanks!
Many Thanks, you made my day man!
Thanks for sharing
It worked! Thankss!!!
Big help – Thank you.
Thank you for solution. It works like a charm. 😀
Big thanks! Works in Ventura!
Thank you!
Thanks so much for this.
Thanks