Open In App

How To Resolve Permission Denied Error On Ubuntu/Debian?

Last Updated : 28 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 secure 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.

Common Causes of "Permission Denied" Errors

  • Trying to execute a command that requires root or admin-level access without the 'sudo' command.
  • Attempting to read, write, or execute a file without the necessary permissions.
  • The current user does not own the file or directory, preventing them from making modifications.

Methods to Resolve Permission Denied Error On Ubuntu/Debian

In this article, we will learn how to fix them with the following methods:

Let's explore all the methods one by one.

Method 1: Sudo command missing

Step 1: Identify the Need for 'sudo'

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: Add the 'sudo' Command

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:

 

After entering the command, you will be prompted to enter your password. This grants the necessary permissions to install the application.

Method 2: Insufficient permissions to access the files

If you have insufficient permissions to access or modify a file, you can change the file permissions using the 'chmod' command.

Step 1: Attempt to Access the File

For instance, if you try to read a file named 'geeks.txt':

$ cat geeks.txt

The output is 

 

Step 2: Modify Permissions with 'chmod'

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

$ chmod +rwx geeks.txt
$ cat geeks.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: Check Current File Ownership

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.

 

This command will display the current owner and group associated with the file.

Step 2: Change the File Owner

Now add the user geeks using the following command.

sudo chown geeks geeks.txt

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

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

Conclusion

"Permission Denied" errors in Linux can be frustrating, but understanding how to manage user permissions, ownership, and access rights effectively is key to resolving these issues. Using commands like 'sudo', 'chmod', and 'chown' allows you to gain the necessary access and maintain a secure environment. By following the above given methods, you can easily troubleshoot and fix permission-related issues to enhance your Linux experience.


Next Article
Article Tags :

Similar Reads