Files on an operating system usually have permissions, which makes the file accessible to a limited number of people. For example, some files on a computer are only accessible to administrators; other files are only accessible to a specific user.
If you try to run a file that you do not have access to on a Linux machine, you will see a permission denied error. In this guide, we will talk about the cause of this error and how to fix it. Let’s get started.
Bash permission denied
Bash permission denied error occurs when you try to run a file that does not have permission to execute. This can happen if a file can only be executed by a particular user or group of which you are not a member.
On a Linux operating system, there are three types of permissions:
You may be allowed to read and write a file without having execute privileges. Therefore, if you encounter a Bash permission denied be sure to check if you have permission to run the file. You can check if you have permissions on a file using the following command:
This command will give information about file permissions. We discuss the output of this command in our The Solution section later in the article. Let’s look at an example scenario with the permission denied error, with a corresponding solution.
An example scenario
We have a file named example. SH. We can see this file by running the ls command. The ls command returns the following:
We want to run our example.sh file. To do this, we can use the notation ./:
This command allows us to run the example.sh file which is present in our ./ directory (the directory we are currently viewing). Let’s see what happens when we try to run the file:
Our command returns an error.
Our Bash shell tells us we don’t have permission to run our file. We can check the permissions we have by running the ls -la command:
We have no privileges to run on any of our files. If there was a x after rw in the first entry of the output above, we would know we can run our file. The three characters after the first represent read, write and execute privileges for a user. Our group also does not have write or execute permissions.
To solve this problem, we need to grant ourselves execute privileges:
This command gives our user execute privileges (" x ") to the example .sh file.
We can only run this command if we are allowed to modify the privileges of the file. If this file were protected (owned by root, for example), we wouldn’t be able to edit this file.
The file is owned by system user james so I can change file permissions on my james account. I could also use sudo to change the privileges of the files, although this is not necessary as my user account has the necessary access.
The Bash permission denied indicates that you are trying to run a file for which you are not permitted to run. To resolve this issue, use the chmod u + x command to give yourself permissions. If you cannot use this command, you might need to contact your system administrator to access a file.
Want to know more about Bash? Check out our Guide on how to learn the command line . comes with the best tips on how to learn Bash. You will also find a list of resources to help you accelerate your learning journey.