"zsh: operation not permitted" when trying to run a swift executable in another machine

Hi, I'm trying to share with a friend the release product a executable swift package but she's keeps getting the error "zsh: operation not permitted". I have build it using swift build -c release. What step am I missing?

Shot in the dark: Does the file have executable permission? Try chmod +xing it

3 Likes

It turns out that the problem was that I was sharing the zip file with the executable by Telegram. I sent it by email and it worked fine. :sweat_smile:

A shot in the dark…
Look at the extended attributes via "xattr -l FILE"
Is there a com.apple.quarantine attribute? Try to remove it via
"xattr -d com.apple.quarantine FILE".

4 Likes

A shot in the dark…

This is almost certainly correct.

The operation not permitted error translates to EPERM. This is different from EACCES (Permission denied), which is the error you get if you hit a file system permissions check. You most commonly hit EPERM when the operation was restricted by the App Sandbox, MAC, Gatekeeper, and so on. See On File System Permissions.

If you transfer an executable in a way that quarantines it, it’ll be checked by Gatekeeper. For it to pass this check, the executable must be notarised. See Notarizing macOS Software Before Distribution for those details.

Or, in a situation like this, where you’re transferring the executable between machines via a trusted channel, just manually remove the quarantine.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

5 Likes

Thank you @GreatOm and @eskimo for the the well explained solution!