keepcalculator

06 Numbers and Powers

Permission Denied Terminal Mac? Fix It Now

Card No. 06·73734 · Updated · Standard formula, shown below

If you see “Permission denied” in the Terminal on your Mac, it usually means your user account lacks the necessary read, write, or execute rights for the file or folder you’re trying to access. The fix is typically one of three things: change the file’s permissions with chmod, change its owner with chown, or use sudo to run the command with administrator privileges. This article explains exactly what causes the error, how to diagnose it, and the safest ways to resolve it.

What “Permission Denied” Actually Means

macOS, like other Unix-based systems, controls access to every file and directory through a permission system. Each item has an owner, a group, and a set of three permission triads: read (r), write (w), and execute (x). These apply separately to the owner, the group, and everyone else (often called “others” or “world”).

When you type a command like ./script.sh or cat file.txt, the Terminal checks whether your user account (or the group you belong to) has the required permission. If not, the shell prints Permission denied and stops. It’s not a system malfunction—it’s the operating system enforcing its security model.

Common Causes on a Mac

Several everyday situations trigger this error. Recognizing which one you’re in helps you choose the right fix.

  • Missing execute permission on a script: You downloaded or created a shell script but it isn’t marked as executable. Running ./myscript.sh fails with “Permission denied.”
  • File owned by another user: Files copied from another Mac, an external drive, or a zip archive may be owned by a different user ID. Your account can’t read or modify them.
  • Protected system directories: Trying to write to folders like /Library or /System without admin rights gives a permission error. You need sudo for these.
  • SIP (System Integrity Protection) restrictions: Even with sudo, macOS protects certain system files. You’ll see “Operation not permitted” rather than a classic permission denial, but it’s related.
  • App Sandbox or Full Disk Access: Terminal may lack permission to access certain folders like Desktop, Documents, or Downloads if Full Disk Access isn’t enabled in System Settings.

How to Check Permissions and Ownership

Before changing anything, inspect the file or directory. The ls -l command shows the permission string, owner, and group.

ls -l /path/to/file

The output looks like this:

-rw-r--r--  1 john  staff  1024 Mar 12 10:00 notes.txt

Break it down: the first character (- for a file, d for a directory) is the type. The next nine characters are three triads: owner (rw-), group (r--), and others (r--). Here, the owner can read and write, but not execute. The group and others can only read.

If you need to know who owns it, the third column shows the username, and the fourth shows the group. To see the current user, run whoami.

Fixing It: chmod, chown, and sudo

Once you know the issue, apply the appropriate command. Always start with the least invasive change.

1. Make a script executable

If the error occurs when running a script, add the execute bit for the owner:

chmod +x script.sh

Then run it with ./script.sh. If you want everyone to be able to execute it, use chmod +x script.sh (which actually adds execute for all users by default). For more control, use numeric modes: chmod 755 script.sh gives the owner read/write/execute and everyone else read/execute.

2. Change file ownership

If the file is owned by another user, take ownership with chown. This requires admin rights, so use sudo:

sudo chown yourusername:staff /path/to/file

Replace yourusername with your actual username (check with whoami) and staff with the group you belong to (usually staff or wheel). After this, you can read and modify the file normally.

3. Use sudo for system files

When writing to protected directories, prefix the command with sudo:

sudo nano /Library/Preferences/example.plist

You’ll be prompted for your password. Be cautious—sudo grants full admin power, so only use it when you’re sure the command is safe.

Dealing with SIP and Full Disk Access

Some files are protected even from sudo because of System Integrity Protection. If you see “Operation not permitted” when trying to modify a system file, SIP is blocking you. You generally should not disable SIP—it’s a core security feature. Instead, check if the file is in a location you’re allowed to modify. For user files in Desktop, Documents, or Downloads, ensure Terminal has Full Disk Access:

  1. Open System Settings > Privacy & Security > Full Disk Access.
  2. Click the + button and add Terminal from /Applications/Utilities.
  3. Toggle it on if it isn’t already.

After enabling, quit and reopen Terminal for the change to take effect. This often resolves “Permission denied” when accessing protected user folders.

Common Mistakes and Misconceptions

A frequent mistake is using sudo on a file you simply don’t own but that isn’t protected. This can be dangerous because it changes the file’s ownership to root, and then you might not be able to edit it without sudo every time. Better to use chown to take ownership properly.

Another misconception is that chmod 777 is a good fix. It gives everyone full read/write/execute rights, which is a security risk. Use it only for temporary files on a single-user system, and never on scripts or configuration files that contain sensitive data.

Also note that the error message can be misleading. If you try to cd into a directory without execute permission, you get “Permission denied” even if you can read the directory listing. The execute bit on a directory is required to enter it.

When to Avoid Changing Permissions

If the file is part of the macOS system (in /System, /Library, or /usr/bin), do not change its permissions or ownership. Doing so can break system functionality or cause boot issues. Instead, use the appropriate system tool or reinstall the component. If you’re unsure whether a file is essential, search online for its name before modifying it.

Similarly, if you’re working with files on a network drive or a mounted disk, the server may enforce its own permissions. Changing local permissions won’t help; you need to adjust permissions on the server or mount the volume with the correct credentials.

Frequently Asked Questions

Why do I get “Permission denied” when running a script I just created?

New files are created without the execute bit by default. Run chmod +x script.sh to add it, then run with ./script.sh. If the script has a shebang like #!/bin/bash, it will work after that.

What does “Operation not permitted” mean in Terminal on Mac?

It’s a different error from “Permission denied.” It often means SIP is protecting the file, or Terminal lacks Full Disk Access. Check System Settings > Privacy & Security > Full Disk Access and add Terminal if needed.

How do I fix “Permission denied” for a file on an external drive?

The drive may be formatted with a filesystem that doesn’t support Unix permissions (like FAT32 or exFAT), or the file’s owner is different. Try copying the file to your Mac’s internal drive first, then change ownership with sudo chown yourname:staff file.

Is it safe to use sudo chmod 777 on a file?

No. It gives every user full read, write, and execute permissions, which is a security risk. Use the minimum permissions needed, such as chmod 755 for a script or chmod 644 for a readable file.

Why can’t I change permissions on a file even with sudo?

If the file is in a system-protected location (like /System), SIP blocks modifications even for root. You should not disable SIP; instead, find an alternative way to achieve your goal, or copy the file to a user directory.

How do I make Terminal always use sudo for a command?

You can’t make a command always run as root without typing sudo. But you can create an alias in your shell configuration file (like ~/.zshrc) that includes sudo, e.g., alias update='sudo softwareupdate -i -a'. Then type update and it will prompt for your password.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →