Monday, January 29, 2018

How to resolve permission denied Linux error

https://linuxroutes.com/avoid-permission-denied-linux-error

This article will teach you quickly what is permission denied Linux error. And also what ways you can avoid permission denied error in Linux.permission denied Linux

What is permission denied Linux error?

This error comes when you try to list files or try execute the file inside the directory where you don’t have sufficient permission. Since Linux operating system is very particular about its security aspect.

Example of Permission denied Linux error

Let’s say you are a normal user who is trying to list or trying change the directory inside the /root file-system. Since you do not have sufficient permissions system will respond with permission denied error message as below:
One way to avoid such error is to switch to root user using su – command. However this solution is not recommended since it will gain unnecessary access to all the root file system.

How to resolve Permission denied Error

  • Resolving Permission denied error related to script execution:

Let’s say you have created a shell script for performing any task. but when you try to execute the script you may end with below error due absence of permission denied error.
Now to avoid such case you need to add execute permission “x” to the file myshell.sh using chmod command as below:
In the last output you can see that there is “x” (execution) permission added after chmod command. So next time when you try to execute the shell script , it will execute without any error.

Resolving permission denied Linux error while listing or writing to a file

In this type of permission denied error you try to list or write the file in which you do not have sufficient permission to do so as below:
If you look at the permissions of the “myfolder” directory using ls -l command you will come to know about the permissions.
As per the permission given in above output only owner of the directory who is root can have all permission that is read, write and execute.  So in such case you need to change the permission of the directory to read using below chmod command:
Now this time when normal user manmohan try to list directory he will not get the permission denied error.
In case you want to have write permission on this directory you need to specify w flag as well in chmod command as below:
Same is applicable to file level permission as well.
One more way is to changing the ownership of the directory using chown command. Since in our example we are getting error for user manmohan we will change ownership of the directory  “myfolder” using below command.
Since manmohan user is now the owner of the directory he can able to do any operation on the directory. In case you want to recursive permission do not forget to add -r while chown command as below:
  • Resolving permission denied Linux error for specific user

In above method of changing the permission using chmod is not suitable as per my opinion. Because when you give permission to others, it will be open for all the users within the system. Which is wrong in terms of security perspective.  To resolve this error specific to user you can implement it using access control list or ACL. Follow my article on Access control list ACL for the same.

Download Free book

Get your free copy of Linux command line Cheat Sheet!!!!

Download This Book: Click Here!!

No comments:

Post a Comment