Opening a file in macOS is quite easy. You just need to double-click on it — and voila! It shouldn’t take long to open a file on your Mac. Another way to open a file is via Terminal. Just run a command and set the directory where the file is saved and you should be able to open it without any hassle.
Unfortunately, that’s not always the case. There have been instances when the Terminal is getting “permission denied” error in Mac when opening a file. A simple command shouldn’t give out this error. This only means that there is something wrong with either your file or macOS itself.
Here are some “Permission Denied” example errors:
- zsh: permission denied: ./foo.rb
- Bash: bash: ./foo.rb: /usr/local/bin: bad interpreter: Permission denied
- aftheers-MacBook-Air:scripts root# ./ArduinoWifiShield_upgrade.sh
- -sh: ./ArduinoWifiShield_upgrade.sh: Permission denied
This is a common error that has been hounding Mac users for a long time. It is not something new, but there have been several reports recently of Mac users getting “permission denied” error in Mac after upgrading to Catalina and Big Sur.
There are a lot of things that could go wrong when you run a command in Terminal, so encountering this error is not surprising. But this error can still be very annoying, especially if you have no other way to open the file. For instance, you want to open a file with no associated program or does not respond to clicks.
What Is Permission Denied in Terminal to Open a File?
Just like what the name says, this is a permission error that prevents Mac users from opening a file using commands. It can occur with sudo commands or even bash commands. According to several reports, the Permission Denied error can also happen even when the file is being opened in root.
Most of the reports say that the error appears when they are trying to open the file installer via Terminal. When the file is dragged to the Terminal window, the “Permission Denied” error pops up. However, this can also happen with any other file.
Why You’re Getting “Permission Denied” Error in Mac
You will most likely encounter the “Permission Denied” error if you are trying to install a program or modify a file that is locked. It could be because you do not have administrator privileges or because the creator of the file used chmod to lock the file. This error is an indication that your command is attempting to write to a directory that your user account does not own.
You can check the permissions of the file in question by typing in ls -l file.ext in the Terminal. The “file.ext” represents the file and extension of the file you’re trying to open or modify. You can also try to force a command that requires administrator permission using “sudo,”.
Another reason you are getting this error is because you probably entered an incorrect command. Check for errors in your syntax and make sure you’re trying to use the right command. If you’re trying to run an application, make sure that the program command is valid and installed on your computer.
How to Fix Permission Denied Error in Mac
When you’re getting this error, the first thing you need to do is try to open the file using the normal method. Double-click on the file to see if you are able to open it. If you’re not successful, then you can try some of the solutions below.
But before you proceed, make sure to optimize your Mac using Outbyte MacRepair to prevent other issues from popping up. It would also clean up your system to make your processes run smoothly. Once done, restart your Mac and check out our troubleshooting guide.
Step 1: Check your permissions.
As mentioned earlier, this error usually happens because you do not have sufficient permissions to access the file. To check whether this is the case:
- Launch Terminal from the Utilities folder.
- Type the following command, and add a space after the final character. DO NOT press Enter: ls -l
- Drag the file you want to open and drop it into the Terminal window. This will automatically append the file’s location to the existing command. However, this will not actually move the file.
- Now click on the Terminal window and press Enter.
This will show you whether you have permission to write or modify the file.
Step 2: Change the ownership of the directory.
Take ownership of the directory with the chown command before attempting to write to it.
You can enter this command in Terminal, then press Enter: chown -R $USER:$USER /path/to/directory
Change $USER with the current logged in user and /path/to/directory with the path to where you want to write to.
Step 3: Give Terminal full access to the disk.
It is also possible that the Terminal does not complete access to the disk, which is why you can’t open the file using commands. To fix this, go to System Preferences > Security & Privacy > Privacy panel, then add Terminal to the list of apps that are able to control your computer.
Step 4: Use SUDO commands.
The sudo command executes the commands that follow it superuser or root privileges. This command should allow you to execute almost any command from the Terminal. To do this, simply add sudo before the original command. Here are sample commands:
- sudo chmod 755 /dvtcolorconvert.rb
- sudo chmod 755 ~/Themes/ObsidianCode.xccolortheme
You will be prompted to enter your password if this is your first time using the sudo command. But after that, you won’t have to enter it every time you use a sudo command.
Getting “permission denied” error in Mac when you’re trying to access a file is not a huge problem if you are able to open the said file by double-clicking. However, most of the time, users who experience this error are almost always unable to open the file using conventional methods. Since this is a permission error, you need to make sure you have enough privileges to access it. The steps above should guide you on what to do. This is quite helpful for Mac users who are not familiar with using commands or the Terminal.