Executing terminal commands or shell scripts in macOS often fails with the security rejection: Operation not permitted. This error occurs even when running commands prefixed with sudo from an elevated root account. Whether you are attempting to list contents of your Desktop (ls ~/Desktop), access user Documents or Downloads, modify system backups, or run automation scripts, macOS terminates file access. This barrier is enforced by Apple Transparency, Consent, and Control (TCC) framework and System Integrity Protection (SIP), which isolate personal user directories from terminal binaries by default.
Resolving ‘Operation not permitted’ requires granting Full Disk Access permissions to Terminal or iTerm2 in macOS System Settings, managing extended file attributes, and understanding TCC policy boundaries.
Why Does Root/Sudo Fail with ‘Operation Not Permitted’?
In traditional Unix systems, root access overrides all file permissions. However, modern macOS separates traditional Unix permissions (POSIX) from Apple Privacy Protections (TCC). Even the root user is blocked due to several security layers:
- Full Disk Access Restrictions: macOS quarantines personal user folders (Desktop, Documents, Downloads, Mail, Safari, and Time Machine) behind the TCC sandbox. Applications, including Terminal, cannot read or write to these locations until granted explicit permission by the user.
- System Integrity Protection (SIP): Core system directories (such as
/System,/usr/bin, and/sbin) are mounted on a cryptographic Sealed System Volume (SSV) that rejects all modification even under root elevation. - Extended Security Attributes (com.apple.quarantine): Files downloaded from the internet carry quarantine flags that trigger sandboxing filters during command-line execution.
- Third-Party Terminal Emulators: Using iTerm2, Alacritty, Warp, or VS Code integrated terminals without configuring dedicated privacy entitlements.
Method 1: Grant Full Disk Access to Terminal in System Settings
The definitive solution for standard user directory access is granting Full Disk Access in macOS Sequoia, Sonoma, or Ventura:
- Click the Apple menu in the top-left corner and select System Settings.
- Scroll down the left navigation sidebar and click Privacy & Security.
- In the right pane, locate and click Full Disk Access.
- Look for Terminal in the list of applications.
- Toggle the switch next to Terminal to the On position. Enter your Mac administrator password or Touch ID to confirm.
- If you use an alternative terminal emulator (such as iTerm, Warp, or Visual Studio Code), ensure its toggle is also switched On.
- If your terminal application is currently running, a prompt will appear stating: Terminal will not have full disk access until it is quit. Click Quit & Reopen.
- Test directory traversal by running
ls ~/Desktoporls ~/Library/Mailin your refreshed terminal session.
Method 2: Add Terminal Manually if Missing from the List
If Terminal is not listed under the Full Disk Access pane:
- In System Settings > Privacy & Security > Full Disk Access, scroll to the bottom and click the plus (+) icon. Authenticate with your password.
- In the Finder sheet that opens, press Command + Shift + G to bring up the path dialogue.
- Enter:
/System/Applications/Utilities/and press Return. - Select Terminal.app and click Open.
- Ensure the toggle is enabled and relaunch Terminal.
Method 3: Remove Extended Quarantine Attributes
If ‘Operation not permitted’ occurs when launching a specific compiled binary or downloaded script:
- Inspect whether the file carries an Apple quarantine flag:
xattr -l script.sh - If
com.apple.quarantineis present, strip the attribute completely:xattr -d com.apple.quarantine script.sh - Ensure the file has executable permissions:
chmod +x script.sh - Execute the script again.
Method 4: Understanding Protected System Boundaries (SIP)
If you are attempting to modify files under /System, /usr/bin, or /bin, Full Disk Access will not grant write access. These partitions are protected by System Integrity Protection (SIP) and are mounted as read-only cryptographic snapshots. Rather than attempting to bypass or disable SIP, modern macOS best practices dictate placing custom scripts and compiled binaries in /usr/local/bin or Homebrew’s /opt/homebrew/bin directory.