Running a command, running a maintenance script, or managing files in macOS Terminal—even when prefixing commands with administrative privileges using sudo—only to be blocked by the error message “Operation not permitted” is a common frustration for Mac power users and developers. Unlike traditional UNIX environments where the root superuser possesses unrestricted filesystem authority, modern releases of macOS (macOS Sequoia, Sonoma, Ventura, and Monterey) enforce a multi-layered security architecture governed by System Integrity Protection (SIP) and Apple’s Transparency, Consent, and Control (TCC) framework. Under this model, applications—including Terminal, iTerm2, and VS Code—are prohibited from accessing protected user directories (such as Desktop, Documents, Downloads, Mail, Time Machine backups, and removable media) unless explicitly granted Full Disk Access by the user. This technical troubleshooting guide explains macOS permission security and details step-by-step methods to resolve the error.
Why Does macOS Terminal Display ‘Operation Not Permitted’?
The root user in macOS is no longer omnipotent. Understanding the security mechanisms clarifies why sudo fails:
- Transparency, Consent, and Control (TCC) Restrictions: macOS isolates personal data domains (Documents, Desktop, Downloads, Photos, Safari data, and Mail) inside TCC databases. Running commands against these directories without explicit TCC consent triggers “Operation not permitted”.
- System Integrity Protection (SIP): Introduced in OS X El Capitan, SIP locks critical operating system directories (including
/System,/bin,/sbin, and/usr) against modification, even by the root user. - Extended File Attributes (Quarantine / ACLs): Files downloaded from the internet or created by sandboxed apps contain extended attributes (
com.apple.quarantine) or Access Control Lists (ACLs) restricting script execution. - Third-Party Terminal Emulators Missing Entitlements: Using alternative terminals such as iTerm2, Warp, Alacritty, or integrated editor terminals without individual privacy permissions.
Method 1: Grant Full Disk Access to Terminal in System Settings
Granting Full Disk Access exempts your terminal emulator from TCC file isolation, allowing it to navigate and manipulate all user directories.
- Click the Apple menu () in the top-left corner and select System Settings.
- In the left sidebar, click on Privacy & Security.
- Scroll down in the right pane and click on Full Disk Access.
- Look for Terminal in the list.
- Toggle the switch next to Terminal to On. Enter your Mac administrator password or Touch ID when prompted.
- If you use third-party terminals or editors (such as iTerm, VS Code, or Warp), toggle them On as well.
- If Terminal is not in the list, click the + (plus) button at the bottom, navigate to
/Applications/Utilities/Terminal.app, and click Open. - When prompted to “Quit & Reopen”, click Quit & Reopen to apply the security token immediately.
Method 2: Remove Quarantine Extended Attributes from Files
If the error occurs when executing a downloaded binary or shell script, macOS Gatekeeper’s quarantine flag may be blocking invocation.
- Open Terminal.
- Inspect the extended attributes of the target file or directory:
xattr -l path/to/file_or_script - If the output displays
com.apple.quarantine, strip the attribute by executing:xattr -d com.apple.quarantine path/to/file_or_script - To recursively clear quarantine flags from an entire project directory:
xattr -rd com.apple.quarantine path/to/directory - Re-run your command or script to verify successful execution.
Method 3: Reset TCC Privacy Permissions for Terminal
If privacy permissions have become corrupted inside macOS’s internal TCC database, resetting the permission schema forces a fresh authorization prompt.
- Open Terminal.
- Run the following command to reset all System Integrity TCC permissions for Terminal:
tccutil reset All com.apple.Terminal - If using iTerm2, run:
tccutil reset All com.googlecode.iterm2 - Restart Terminal and attempt to access your target folder. macOS will present a native pop-up dialogue asking: “Terminal would like to access files in your Documents folder”. Click Allow.
Method 4: Check for Immutable Flags and ACLs
Certain system files or repository checkouts contain BSD system immutable flags (uchg or schg) preventing modification.
- Check if the file has an immutable flag set:
ls -lO path/to/file - If the flags column displays
uchg(user immutable) orschg(system immutable), remove it using:chflags nouchg path/to/file - If standard file permissions were modified, restore read/write access:
chmod +rw path/to/file
Method 5: Verify System Integrity Protection (SIP) Scope
If you are attempting to modify files located in read-only system root partitions (such as /System or /usr/bin), SIP intentionally prevents changes regardless of permissions.
- Check the status of SIP in Terminal:
csrutil status - Modern macOS systems use a cryptographically sealed System volume (SSV). Modifications to core operating system components should be placed in
/usr/localor/opt/homebrewinstead of modifying root system paths.