How to Fix ‘zsh: Permission Denied’ in macOS Terminal

Attempting to execute a shell script (./script.sh), run a downloaded binary, or launch command-line developer tools in the macOS Terminal only to receive the response “zsh: permission denied: [filename]” is a common hurdle on Mac systems. Because Apple’s default shell (Zsh) strictly enforces POSIX file permission modes and macOS security sandboxes, it refuses to execute any file lacking explicit execute bits.

This barrier is typically caused by missing execute (+x) permissions, running scripts from directories protected by macOS System Integrity Protection (SIP), Gatekeeper quarantine flags applied to downloaded files, or attempting to execute a directory path instead of a file.

Security Trigger Technical Explanation Direct Solution
Missing POSIX Execute Bit File mode lacks executable flag (e.g. -rw-r--r-- instead of -rwxr-xr-x) Grant execute permission via chmod +x
macOS Gatekeeper Quarantine com.apple.quarantine extended attribute blocks terminal launch of downloaded files Remove quarantine flag using xattr -d
Incorrect Command Syntax User typed directory path or omitted shell interpreter Prepend appropriate interpreter (bash, python3, zsh)
Root / Administrator Ownership File is owned by root or another user account without read/execute access Reassign ownership via chown

Method 1: Grant Execute Permission Using chmod +x

When you create a shell script or download a binary from GitHub, text editors and web browsers save files with standard read/write permissions (644), omitting the vital execute bit required by Zsh.

  1. Open Terminal (located in Applications > Utilities or via Spotlight search).
  2. Navigate to the folder containing your script:
    cd /path/to/folder
  3. Inspect the current permissions of the file by running:
    ls -l filename.sh
  4. If the output begins with -rw-r--r--, execute permissions are absent. Add the execute bit by typing:
    chmod +x filename.sh
  5. Run your script again:
    ./filename.sh

Method 2: Remove the macOS Quarantine Attribute

Files downloaded via web browsers (Safari, Chrome) or chat apps receive a security tag called com.apple.quarantine. macOS Gatekeeper prevents Terminal from executing quarantined scripts even if chmod +x has been applied.

  1. In Terminal, check if your file carries extended attributes:
    xattr filename.sh
  2. If the output displays com.apple.quarantine, remove the attribute:
    xattr -d com.apple.quarantine filename.sh
  3. To recursively clear quarantine attributes from an entire directory of tools, run:
    xattr -r -d com.apple.quarantine /path/to/directory
  4. Execute the file again.

Method 3: Explicitly Call the Script Interpreter

If a script lacks a valid shebang line (e.g. #!/bin/zsh or #!/bin/bash) at the very top of the file, Zsh does not know which interpreter to use when invoking ./filename.sh.

  1. Instead of executing the file directly with ./filename.sh, explicitly invoke your desired shell interpreter:
    zsh filename.sh
    or:
    bash filename.sh
    or for Python scripts:
    python3 script.py
  2. To make the script self-executable, open it in a text editor and ensure line 1 reads:
    #!/bin/zsh

Method 4: Fix File Ownership with chown

If the file was installed using sudo or copied from another user account on your Mac, your current user account may lack permission to read or execute the file.

  1. Check the file’s owner:
    ls -l filename.sh
  2. If the owner is root or another username, transfer ownership to your active user account:
    sudo chown $(whoami):staff filename.sh
  3. Enter your macOS administrator password when prompted.
  4. Grant read and execute permissions:
    chmod 755 filename.sh

Method 5: Grant Full Disk Access to Terminal

macOS Transparency, Consent, and Control (TCC) restricts terminal applications from reading files inside protected user folders (Documents, Desktop, Downloads) or external volumes unless explicit authorization is granted.

  1. Click the Apple menu in the top-left corner and select System Settings.
  2. Click Privacy & Security in the left sidebar.
  3. Scroll down and click Full Disk Access.
  4. Locate Terminal (and any third-party terminal like iTerm2) in the list.
  5. Toggle the switch to the On position.
  6. Enter your administrator password or Touch ID when prompted.
  7. Restart Terminal to apply the permissions.

Safely Executing Commands in macOS

Never bypass permissions by running unknown scripts with sudo (superuser privileges) simply to silence a permission denied warning. Running unvetted scripts as root can overwrite critical system dependencies. Always inspect the contents of an unfamiliar shell script using cat filename.sh or nano filename.sh before granting execution rights.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.