PDF download Download Article
Resolve command and permission errors in Terminal
PDF download Download Article

Did you run into a Zsh: Permission Denied error when trying to run a command or script in Terminal on your Mac? If so, don’t worry–these errors are usually pretty easy to resolve by fixing problems with your command syntax or changing your file permissions. In this article, we’ll explain what the error means, as well as the most common ways to fix it.

How to Fix the Zsh: Permission Denied Error

This error usually means you don’t have the right permissions to access a file on your Mac. Make sure you entered the command and file name correctly, and that the file is executable if it's a script or program. You might need to grant yourself write/execute access or give yourself ownership.

Section 1 of 6:

What does the Zsh: Permission Denied error mean?

PDF download Download Article
  1. 1
    This error usually means you don’t have the right permissions. It might come up if the file you’re trying to access is locked, or if you don't have permission to read, write, or execute the file. It can also happen if Terminal doesn’t have full access to the drive where the file is located.
  2. 2
    It can also happen if your command isn’t formatted correctly. The Zsh: Permission Denied error can also be a sign of a problem with the command or script you’re attempting to execute.
  3. Advertisement
Section 2 of 6:

Fixing Command Errors

PDF download Download Article
  1. Carefully review the command for errors. If you mistyped a command in Terminal or copied and pasted it incorrectly, you might trigger a Permission Denied error. Double-check your command for typos, missing text or symbols, or other syntax errors. It could even be something as simple as accidentally swapping an em-dash (—) for a pair of hyphens (--).
    • It’s often safer to copy and paste a command than to try to type it out, especially if it’s something long and complicated.
Section 3 of 6:

Checking & Fixing File Permissions

PDF download Download Article
  1. 1
    Use the ls -l command to check file permissions. This command will tell you whether you have read, write, and execute permissions for the file you’re attempting to access or modify. Here’s how to use it:
    • In Terminal, enter the command ls -l followed by a space. Don’t press Return yet.
    • Drag and drop the file or folder you’re working on into Terminal from Finder or your desktop. The correct path to the file or folder will appear in your Terminal command.
    • Press Return . Check the string of letters in front of the file(s) to find your permissions:
      • “r” indicates you have read access (i.e., you can view the contents of the file).
      • “w” means you have write access (you can modify the file).
      • “x” means you have permission to execute the file (or open the folder).
      • “-” means you do not have any access to the file.
      • So, for example, a string like -rwxr-xr-x means that the owner of the file has full access, while other users of your computer have read and execute access.
  2. 2
    Change file permissions if necessary. Once you’ve granted yourself read/write/execute privileges, you may be able to execute your command without triggering the Zsh: Permission Denied error. There are a couple of different ways to do this.
    • In Terminal, you can change permissions using the chmod command:
      • If the file is a program or script you are trying to run, you'll need to make it executable. To do this, just type chmod +x filename and press Return , replacing filename with the name of the file.
      • If you are the owner of the file, you can also use chmod +r to give yourself Read permissions, chmod +w to give yourself Write permissions, or a combination of 2 or 3 options (example: chmod +rx gives you Read and Execute permissions).
      • To change read, write, and execute permissions for anyone using this Mac, type chmod followed by the account type, any modifiers, and the privilege type you’re trying to change. For example:
        • chmod ugo=rwx Desktop/test1.docx would give all users (“u” for owner, “g” for group, and “o” for others) full read, write, and execute access for the file “Desktop/test1.docx”.
        • Alternatively, you can use numeric notation to grant permissions. In this case, the command would look like chmod 775 Desktop/test1.docx .
      • If you’re not logged in with the account that owns the file you’re trying to modify, you’ll have to preface this command with sudo .
        • For example, the command above would become sudo chmod ugo=rwx Desktop/test1.docx .
  3. 3
    You can also change file permissions in Finder. To do so:
    • Right-click or Ctrl -click the file or folder in Finder and select Get Info .
    • Scroll down to Sharing & Permissions . You may need to click > next to the header to expand this section.
      • Click the dropdown in the Privilege column next to your username and select Read & Write (if it’s not already selected).
  4. Advertisement
Section 4 of 6:

Changing Directory Ownership

PDF download Download Article
  1. 1
    Enter the chown command in Terminal. This method allows you to change the ownership of the file you’re trying to access, which may grant the missing permissions you need. In most cases, you must combine chown with the sudo command, granting you root/superuser privileges to execute the command. Enter the following text in Terminal:
    • sudo chown -R $(whoami)
    • Add a space after this command, but don’t press Return yet.
  2. 2
    Drag and drop the file or folder into Terminal. This will cause the correct file path to appear after the command. Press Return to execute the command.
    • At this point, you’ll be prompted to enter your password. You won’t be able to see it as you’re typing it in. Press Return when you’re done.
    • Once you’ve successfully executed the chown command, try running the problematic command or script again. This time, you might not see the Zsh: Permission Denied error.
  3. Advertisement
Section 5 of 6:

Granting Full Disk Access to Terminal

PDF download Download Article
  1. 1
    Open System Settings . Sometimes the problem isn’t with your user privileges, but with Terminal itself. If Terminal doesn’t have full access to your hard disk, it may not be able to execute certain commands. To grant full access, start by going to Apple menu > System Settings in the toolbar at the top of your screen.
  2. 2
    Click Privacy & Security . It’s in the menu bar on the left side of the window.
  3. 3
    Select Full Disk Access . In older versions of macOS, you might need to click the Privacy tab at the top of the window first.
  4. 4
    Toggle on the switch next toTerminal. If you don’t see Terminal in the list, click the + button at the bottom of the list of apps and utilities. Enter your password or use Touch ID to verify your identity when prompted. In the window that opens, navigate to Applications > Utilities and select Terminal , then click Open to add it to the list.
    • Once full disk access for Terminal is on, try again to execute your command.
  5. Advertisement
Section 6 of 6:

Using SUDO

PDF download Download Article
  1. Try running your command with sudo . SUDO stands for “superuser do.” This command temporarily grants you root or superuser privileges . Adding SUDO before a command in Terminal may be enough to grant the permissions you need to avoid the Zsh: Permission Denied error.
    • For example, you may be able to run an app with root privileges by entering the command sudo /Applications/YourAppName.app/Contents/MacOS/YourAppName (replacing “YourAppName” with the name of the app).
    • If this doesn’t work, you might have to enable the root account on your Mac , which is much riskier than using the SUDO command. This approach is not recommended unless absolutely necessary.

Expert Q&A

Ask a Question
      Advertisement

      Tips

      • When attempting to run commands in Terminal, it’s usually best to be logged in as an administrator on your Mac.
      • If you continue to run into problems, it might help to completely quit and reboot Terminal. You can also try restarting your Mac.
      • Most of these solutions also work in the Linux command line.



      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Is this article up to date?

      Advertisement