How To Resolve Permission Denied Error On Ubuntu/Debian?

Linux is a community of open-source Unix-like operating systems that are based on the Linux Kernel. Linux distributions are constructed in such a secured way that a user cannot make changes unless he/she has administration access. Users who are first time exploring Linux encounter the problem of Permission being Denied. In this article, we will learn how to fix them with the following methods.

  • Sudo command missing
  • Insufficient permissions to access the files
  • Change ownership of the file

Let’s explore all the methods one by one.

Method 1: Sudo command missing

Step 1: This is one of the very common mistakes that experienced Linux users also make and has nothing wrong with your system or files. The sudo command allows you to access the files, and folders, and change settings that are accessible to only a root user. For example, here we are installing a new application and the user who is installing should be a root user. 

First, we enter the command

apt-get install neofetch

And we get the following error.

 

Step 2: Now add the sudo command, after entering the following command, you are required to enter the password.

sudo apt-get install neofetch

The output is as follows:

 

Method 2: Insufficient permissions to access the files

Step 1: Some files don’t have the required permission for accessing. In the following example, we want to read a file but we don’t have sufficient permissions.

$ cat Beginner.txt

The output is 

 

Step 2: Now we will change the access permission using the chmod command. The +rwx adds the read-write access.

$ chmod +rwx Beginner.txt
$ cat Beginner.txt

The output is as follows

 

The chmod has the following commands:

  • r: It means the read permission.
  • w: It means write permissions
  • x: It means execution permissions.
  • +: It provides permission. 
  • : It removes the permission. 

Method 3: Change ownership of the file

This also gives a Permission Denied error to a user in a mixed system when the user doesn’t have the access to a particular file. We can add users using the chown command.

Step 1: First, check the users who have access using the following command.

ls -l

Only a single user and a single group have access to read, write and execute as can be seen in the output.

 

Step 2; Now add the user Beginner using the following command.

sudo chown Beginner Beginner.txt

Now check the owners of the file. The output is as follows:

 

So the user Beginner now has the access to the text file.


Contact Us