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


Posted

in

by

Comments

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

  1. Jordano Avatar
    Jordano

    Thank you!

  2. Jim Avatar
    Jim

    You saved me with this. I literally love you right now

  3. Teus Avatar
    Teus

    That worked for me, thank you!

  4. Jamie Avatar
    Jamie

    Excellent. This was most helpful, thanks a lot.

  5. Oscar Avatar
    Oscar

    Great, I was dancing with chmod to no avail.
    Thank you!

  6. Yu Avatar
    Yu

    Thank you!

  7. Glory Avatar
    Glory

    Thank you for that. It seems a new problem because my script that written years ago still runs.

  8. Skippy Avatar

    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…

  9. Sahil Avatar
    Sahil

    You saved me. Indebted

  10. Janosh Avatar
    Janosh

    Thanks! Sometimes Apple makes life difficult for devs.

  11. saghazade Avatar
    saghazade

    i am seriously thankful of you!

  12. Maria Avatar
    Maria

    Thank you so much for the tip!

  13. Ben Avatar
    Ben

    Very, very helpful. Thank you!

  14. musa Avatar
    musa

    thanks bro saved my day

  15. endyk Avatar
    endyk

    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.

  16. pr Avatar
    pr

    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!

  17. Gabri Avatar
    Gabri

    Many Thanks, you made my day man!

  18. Alan Avatar
    Alan

    Thanks for sharing

  19. Melissa Avatar
    Melissa

    It worked! Thankss!!!

  20. Leif Stenfeldt Avatar

    Big help – Thank you.

  21. Cenk Avatar
    Cenk

    Thank you for solution. It works like a charm. 😀

  22. Kari L Avatar
    Kari L

    Big thanks! Works in Ventura!

  23. ryan Avatar
    ryan

    Thank you!

  24. Christopher Hughes Avatar
    Christopher Hughes

    Thanks so much for this.

  25. Jyotsna Avatar
    Jyotsna

    Thanks

  26. barny Avatar
    barny

    what if I don’t want to give access and still want to run *.sh file, is there any alternative solution like sudo?

  27. janus Avatar
    janus

    Thank you! you are a live saver!

  28. Jose Avatar
    Jose

    You save my day. Awesome thanks for this info!

  29. David Vannucci Avatar
    David Vannucci

    alternatively you can run your script in a different shell `bash ./script.sh`

  30. Ivan Avatar
    Ivan

    Thank you very much! Just a few hours and Google gave you your site) thanks for sharing, good luck and success in everything)

Leave a Reply

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