How To Resolve Permission Denied Error On Ubuntu/Debian?
Last Updated :
28 Aug, 2024
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.
Similar Reads
How To Solve Scp Permission Denied Error
SCP (Secure Copy Protocol) is a convenient way to transfer files securely between a local host and a remote server. However, encountering a "Permission Denied" error during an SCP transfer can be frustrating, especially when you have the necessary permissions. In this article, we'll explore the vari
4 min read
How to Fix - rm: Cannot Remove Directory/: Permission Denied
In Linux, file removal, particularly directories, is a common task performed using the rm command. However, encountering a "Permission Denied" error can hinder this process, often due to insufficient permissions or system restrictions. Since, encountering the error "rm: Cannot Remove Directory/: Per
3 min read
How To Fix Error: Permission denied (publickey)?
The error message Permission denied (publickey) is a common issue that Git users encounter when attempting to connect to a remote repository, particularly when using SSH for authentication. This error indicates that the SSH key required for authentication is not recognized or properly configured. In
3 min read
How to Fix: PermissionError: [Errno 13] Permission Denied in Python
When your Python code encounters a situation where it lacks the necessary permissions to access a file or directory, it raises PermissionError: [Errno 13] Permission denied in Python. This article will explore how to address the Errno 13 Error in Python effectively.What is PermissionError: [Errno 13
5 min read
How to Fix - Reading A File: Permission Denied on Linux
In this article, we will see how to fix when a permission error occurs while reading any file in Linux. We'll see how to fix that and also why that error occurs, and its common causes so that in future you will be able to solve those kinds of errors yourself. We'll learn various methods to solve thi
6 min read
Error: Permission denied to access property 'target'
In this article, we will learn about the error, "Permission denied to access property 'target'". The 'target' element returns an element, for which the event, has been called. This error can occur, on any property, not only on the 'target' property. For example, the same error can occur for 'docume
3 min read
How to Fix SSH Failed Permission Denied
SSH, or Secure Shell, is a widely used protocol for securely accessing and managing remote devices over unsecured networks. By using cryptographic network protocols, SSH ensures the confidentiality and integrity of data exchanged between devices, providing a secure channel for communication. Develop
7 min read
How to set up file permissions for Laravel?
Setting up proper file permissions for a Laravel application is crucial for its security and functionality. Laravel, a popular PHP framework, often requires the webserver to have the ability to read and write to specific directories. Incorrect permissions can lead to various issues, such as the inab
4 min read
How to Restore Default Repositories in Ubuntu
Repositories in Ubuntu are servers that contain software packaged into nice .deb or .rpm files containing the programs and libraries you need to set up of packages. A repository or repo is basically a software archive that makes it easy to install new software in your machine. In Linux, systems soft
3 min read
How to Fix Permission Denied (public key) With Gitlab?
The "Permission denied (public key)" error is a common issue encountered when using Git with GitLab on Windows. This error occurs when GitLab is unable to authenticate your system using SSH (Secure Shell). This usually happens due to a misconfiguration of SSH keys, where either the key is missing, n
4 min read