banner



How To Fix Permission Denied In Ubuntu

Files on an operating system usually have permissions, making the file accessible to a limited range of people. For instance, some files on a computer are accessible only to administrators; other files are only accessible to a particular user.

form-submission

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Get exclusive scholarships and prep courses

If you try to run a file to which you have no access on a Linux computer, you will see a permission denied error. In this guide, we're going to talk about the cause of this error and how you can solve the error. Let's begin.

Bash permission denied

The Bash permission denied error happens when you try to run a file which you do not have permission to run. This may happen if a file can only be executed by a particular user or a group of which you are not a member.

form-submission

Find Your Bootcamp Match

  • Career Karma matches you with top tech bootcamps
  • Get exclusive scholarships and prep courses

Do you want to learn more about how a coding bootcamp can help you learn to code? Get started by finding the right bootcamp for you along with unlocking additional information about bootcamp cost and reviews.


On a Linux operating system, there are three types of permissions:

  • Read
  • Write
  • Execute

You can have permission to read and write a file without having execution privileges. Thus, if you encounter a Bash permission denied be sure to check whether you are allowed to run the file. You can check if you have permissions over a file by using the following command:

ls -la

This command will give you 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 featuring the permission denied error, with a corresponding solution.

An Example Scenario

We have a file called example.sh. We can see this file by running the ls command. The ls command returns the following:

81% of participants stated they felt more confident about their tech job prospects after attending a bootcamp. Get matched to a bootcamp today.

The average bootcamp grad spent less than six months in career transition, from starting a bootcamp to finding their first job.

We want to run our example.sh file. To do so, we can use the ./ notation:

This command lets us run the example.sh file which is present in our ./ directory (the directory we are presently viewing). Let's see what happens when we try to run the file:

bash: ./test.sh: Permission denied

Our command returns an error.

The Solution

Our Bash shell is telling us that we do not have permissions to run our file. We can check what permissions we have by running the ls -la command:

-rw-r----- 1 james james 13 Feb 16 12:48 example.sh -rw-r----- 1 james james 13 Feb 16 12:48 example1.sh

We do not have execution privileges over any of our files. If there were an x after the rw in the first entry of the output above, we would know we can execute our file. The three characters after the first one represent read, write, and execute privileges for a user. Our group also does not have write or execute permissions.

To solve this issue, we need to give ourselves execution privileges:

This command gives our user execution ("x") privileges over the example.sh file.

We can only run this command if we are allowed to change the privileges of the file. If this file was protected (owned by root, for example), then we would not be able to change this file.

The file is owned by the james system user so I can alter the file permissions on my james account. I could also use sudo to alter the file privileges, although this is not necessary because my user account has the necessary access.

Conclusion

The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix this issue, use the chmod u+x command to give yourself permissions. If you cannot use this command, you may need to contact your system administrator to get access to a file.

Do you want to learn more about Bash? Check out our How to Learn the Command Line guide. This guide comes with top tips on how to learn Bash. You will also find a list of resources to help you accelerate your learning journey.

How To Fix Permission Denied In Ubuntu

Source: https://careerkarma.com/blog/bash-permission-denied-solution/

Posted by: thomashimageary.blogspot.com

0 Response to "How To Fix Permission Denied In Ubuntu"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel