If macOS Terminal reports “permission denied” when you run a local shell script, first check that you are in the right folder and can read the file. Then add execute permission for your user with chmod u+x, if you intend to run it directly. If that does not resolve the error, check the containing folders and whether macOS is blocking the app that launched the shell from accessing the file. Avoid using sudo or broad permission changes as a first fix.

1. Confirm the script path and your current folder

Open Terminal and move to the folder containing the script. Quote the path if it contains spaces:

cd "/Users/yourname/Projects/My Scripts"
ls -l "./build.sh"

Replace the example path and filename with your own. The ls -l output shows the file’s permissions and owner. If it says the file cannot be found, locate the correct folder or use the full path. A relative path such as ./build.sh means “build.sh in the current folder”; it does not search other folders.

2. Add execute permission to your script

If the file exists and you own it, add execute permission only for your account, then run it from its folder:

chmod u+x "./build.sh"
./build.sh

Apple’s shell scripting guide uses chmod u+x before running a script. The u limits the change to the file owner; +x adds permission to execute. This is narrower than chmod 777, which grants read, write, and execute permissions to everyone. Apple’s Shell Script Basics

If Terminal still says “permission denied,” inspect the permissions again with ls -l. You can also check who owns the file with ls -l and your account name with whoami. If another account owns the script and you lack permission to change it, use a copy in a folder you own or ask the owner or administrator to grant appropriate access. Don’t take ownership of system files as a shortcut.

3. Check folder access and the script’s contents

Execution requires access through the path as well as permission on the script itself. Check the script’s parent folders if you cannot enter its directory or reach the file. If it lives on a shared, external, or managed volume, its access rules may differ; try a copy in a folder you own, provided copying it is appropriate.

If your command instead returns Permission denied while the script is trying to create or modify an output file, the script may be executable but lack write access to that destination. Check the destination folder and the path in the script. Do not make the script writable or executable by everyone just to get past an error.

For a script inside Desktop, Documents, or Downloads, macOS privacy controls may also matter when an app other than Terminal is launching it. In System Settings, open Privacy & Security > Files & Folders and review the listed access for the app involved. Apple describes these controls as per-app access to specific locations. A permissions error from a shell command is not by itself proof that this privacy setting is the cause. Apple: Control access to files and folders on Mac

4. If direct execution fails, run the interpreter explicitly

A script can be readable by your account but lack execute permission. If it is a shell script, you can ask its interpreter to read and run it directly:

/bin/sh "./build.sh"

Use this only when the script is meant for sh. If its first line names another interpreter, such as Bash, use that interpreter instead; the interpreter line (the #! line) specifies how a script is intended to run. Apple recommends including that line for consistency. Apple’s Shell Script Basics

Running through an interpreter can bypass the need for execute permission on the script file, but it does not grant permission to read the script or access the files it uses. If the message changes to a missing interpreter or a syntax error, address that specific issue; it is a different problem from execute permission.

5. Don’t use sudo or disable security protections as a shortcut

sudo runs a command with elevated privileges; it does not fix a missing file, a wrong path, or a script that you have not checked. Use it only when you understand why the task requires administrator access and trust the script’s source and contents. Broad changes such as chmod 777 can expose files to modification by other users.

A shell script’s “permission denied” message is also different from a Gatekeeper warning about an app that macOS cannot verify. Apple’s documented “Open Anyway” steps apply to an app alert and require confidence that the app is trustworthy; they are not a general fix for shell file permissions. Apple: Open apps safely on your Mac

Quick diagnosis

  • ./script.sh: permission denied immediately: check the file’s execute permission; if you own it and trust it, try chmod u+x "./script.sh".
  • The file cannot be found: verify your current folder and exact filename.
  • The script starts, then a command gets denied: check the specific file or folder that command is trying to access.
  • An app alert says the developer cannot be verified: follow Apple’s app-safety guidance only after verifying the app’s source; that alert is separate from the shell’s execute permission.

These checks narrow the problem to the script path, its execute bit, access to a file it uses, or an app-specific privacy or security control. Change only the permission or setting that matches the evidence, and rerun the same command to see whether the error has changed.

Sources