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:
Read
Write
Execute
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:
ls -la
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.
The Solution
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.
Conclusion
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.
Simply put and clear. Thank you for sharing. Javascript Permission Denied and other issues with File handling was always my weak point 😁. I am just not quite sure it is the best method
Manuel Ungerschaft
Moscow | 2023-02-07
I was preparing for my coding interview, thanks for clarifying this - Javascript Permission Denied in Python is not the simplest one. I am just not quite sure it is the best method
Angelo Williams
Boston | 2023-02-07
Simply put and clear. Thank you for sharing. Javascript Permission Denied and other issues with sys Python module was always my weak point 😁. I am just not quite sure it is the best method
Shop
Learn programming in R: courses
$FREE
Best Python online courses for 2022
$FREE
Best laptop for Fortnite
$399+
Best laptop for Excel
$
Best laptop for Solidworks
$399+
Best laptop for Roblox
$399+
Best computer for crypto mining
$499+
Best laptop for Sims 4
$
Latest questions
PythonStackOverflow
Common xlabel/ylabel for matplotlib subplots
1947 answers
PythonStackOverflow
Check if one list is a subset of another in Python
1173 answers
PythonStackOverflow
How to specify multiple return types using type-hints
1002 answers
PythonStackOverflow
Printing words vertically in Python
909 answers
PythonStackOverflow
Python Extract words from a given string
798 answers
PythonStackOverflow
Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?