Cannot open directory permission denied linux

«ls» permission denied even though I have read access to the directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

pi@raspberrypi:~/Desktop $ sudo ls -al total 16 d-wx--x--x 3 pi pi 4096 Jan 12 11:30 . drwxr-xr-x 21 pi pi 4096 Jan 12 11:28 .. -rw-r--r-- 1 pi pi 82 Jan 11 16:13 cmd.txt drwxr-xr-x 6 pi pi 4096 Jan 12 11:30 openvibe-2.0.0-src pi@raspberrypi:~/Desktop $ ls ls: cannot open directory '.': Permission denied 

For some reason you don’t have read permissions to . . You must have done something to change that. Simply do e.g. chmod u+r .

I don’t see an r permission on this line: d-wx—x—x 3 pi pi 4096 Jan 12 11:30 . As @Someprogrammerdude suggests, apply either ‘chmod u+r .’ or something equivalent (e.g. ‘chmod 655 .’) to get it back.

This Q is not about programming as defined for StackOverflow. It may be more appropriate on superuser.com OR raspberrypi.stackexchange.com . Use the flag link at the bottom of your Q and ask the moderator to move it. Please don’t post the same Q on 2 different sites. Please read stackoverflow.com/help/on-topic , stackoverflow.com/help/how-to-ask , stackoverflow.com/help/dont-ask and stackoverflow.com/help/mcve before posting more Qs here. Good luck.

1 Answer 1

As you can see in the output of your command, your directory has incorrectly set permissions.

Permissions on directories

Files and directories both have read, write and execute permissions, but they mean different things. For directories, the permissions have the following meanings:

  • r (read) — When present, the content of the directory may be read.
  • w (write) — When present, the content of the directory may be changed. This means files can be created, renamed and deleted. This requires the x flag to also be set.
  • x (execute) — When present, the directory can be set as the current working directory via cd .

More information can be seen here.

How to fix the problem

The default permissions when creating a new directory on most Linux distributions is drwxrwxr-x , which means the owner and group both have permission to read and modify the contents of the directory, as well as cd ing into it. Any other users may read the contents, but not add any new files.

Читайте также:  Права суперпользователя alt linux

To do this, you need to execute chmod 0775 ~/Desktop

Источник

Ошибка «Permission denied» в Linux

Все операционные системы семейства Linux имеют четко разграниченные права доступа. В своей домашней директории пользователь может делать все, что ему угодно, до тех пор, пока укладывается в отведенные рамки. Попытка выйти за них приводит к появлению ошибки «Permission Denied».

Изменение прав в терминале

Рассмотрим вариант, в котором необходимо прочесть текстовый документ, созданный другим пользователем. Файлы TXT в Linux можно просматривать непосредственно в терминале с помощью команды «cat».

    Заходим в каталог с интересующим нас документом. Набираем команду «cat filename», подставляя вместо «filename» имя нужного файла. На скриншоте показана ошибка «Permission Denied», выглядящая в русской локализации как «Отказано в доступе».

Ошибка «Permission Denied»

Получаем ошибку «Permission Denied» при попытке просмотреть содержимое файла

Просмотр прав доступа командой «ls»

Проверяем права доступа к документу используя команду «ls -l»

Изменение прав доступа командой «chmod»

Используем команду «chmod» и административные права для получения доступа

Просмотр текстового файла командой «cat»

Просматриваем содержимое текстового документа командой «cat»

Изменение прав в файловом менеджере

Разберемся, как выполнить рассмотренную выше операцию в графическом интерфейсе, используя файловый менеджер из дистрибутива.

    Как видно на скриншоте, значок файла изначально имеет дополнительные символы, указывающие на то, что доступ у нему ограничен. При попытке посмотреть содержимое получаем графический вариант ошибки «Permission Denied».

Графический вариант ошибки «Permission Denied»

При попытке открыть текстовый документ получаем ошибку «Permission Denied»

Переключение файлового менеджера в режим root

Открываем меню «Файл» и перезапускаем файловый менеджер от имени root

Окно аутентификации root

Набираем пароль root в окне аутентификации

Контекстное меню файлового менеджера

Открываем параметры файла с помощью контекстного меню

Вкладка «Права» в свойствах файла

На вкладке «Права» разрешаем доступ для группы root и остальных пользователей

Файл, открытый в режиме чтения

Открываем ранее недоступный файл в режиме чтения и изучаем содержимое

В заключение

Как видим, избавиться от ошибки Permission Denied достаточно просто. Решив изменить правда доступа к системным файлам, лишний раз убедитесь, что полностью уверены в своих действиях и понимаете последствия вносимых изменений.

Источник

How to resolve permission denied Linux error

permission denied Linux

This article will teach you quickly what is permission denied Linux error. And also what ways you can avoid permission denied error in 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:

[root@rhel ~]# su - manmohan Last login: Wed Jan 24 14:34:36 UTC 2018 on pts/0 [manmohan@rhel ~]$ ls -l /root ls: cannot open directory /root: Permission denied [manmohan@rhel ~]$ cd /root -bash: cd: /root: Permission denied [manmohan@rhel ~]$ id uid=501(manmohan) gid=501(manmohan) groups=501(manmohan) [manmohan@rhel ~]$

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.

Читайте также:  Hyper threading linux check

How to resolve Permission denied Error

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.

[root@rhel tmp]# ./myshell.sh -bash: ./myshell.sh: Permission denied [root@rhel tmp]#

Now to avoid such case you need to add execute permission “x” to the file myshell.sh using chmod command as below:

[root@rhel tmp]# ls -l myshell.sh -rw-r--r-- 1 root root 27 Jan 25 00:31 myshell.sh [root@rhel tmp]# chmod u+x myshell.sh [root@rhel tmp]# ls -l myshell.sh -rwxr--r-- 1 root root 27 Jan 25 00:31 myshell.sh [root@rhel tmp]#

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.

[root@rhel tmp]# cat myshell.sh echo "My name is Manmohan" [root@rhel tmp]# ./myshell.sh My name is Manmohan [root@rhel tmp]#

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:

[manmohan@rhel tmp]$ cd myfolder/ -bash: cd: myfolder/: Permission denied [manmohan@rhel tmp]$

If you look at the permissions of the “myfolder” directory using ls -l command you will come to know about the permissions.

[root@rhel tmp]# ls -ltr total 4 drwx------ 2 root root 4096 Jan 25 00:48 myfolder [root@rhel tmp]# pwd /tmp [root@rhel tmp]#

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:

[root@rhel tmp]# chmod o+rx myfolder/ [root@rhel tmp]# ls -lt total 4 drwx---r-x 2 root root 4096 Jan 25 00:48 myfolder [root@rhel tmp]#

Now this time when normal user manmohan try to list directory he will not get the permission denied error.

[manmohan@rhel tmp]$ ls -lt myfolder/ total 0 [manmohan@rhel tmp]$ cd myfolder/ [manmohan@rhel myfolder]$

In case you want to have write permission on this directory you need to specify w flag as well in chmod command as below:

[root@rhel tmp]# chmod o+rwx myfolder/ [root@rhel tmp]# ls -lt total 4 drwx---rwx 2 root root 4096 Jan 25 00:48 myfolder [root@rhel tmp]#

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.

[root@rhel tmp]# chown manmohan:manmohan myfolder/ [root@rhel tmp]# ls -l total 4 drwx---rwx 2 manmohan manmohan 4096 Jan 25 00:48 myfolder [root@rhel tmp]#

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:

[root@rhel tmp]# chown -R manmohan:manmohan myfolder/

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.

Читайте также:  Установка linux mint ssd

Download Free book

Get your free copy of Linux command line Cheat Sheet.

Источник

ls cannot open directory Permission denied

  • All categories
  • ChatGPT (11)
  • Apache Kafka (84)
  • Apache Spark (596)
  • Azure (145)
  • Big Data Hadoop (1,907)
  • Blockchain (1,673)
  • C# (141)
  • C++ (271)
  • Career Counselling (1,060)
  • Cloud Computing (3,469)
  • Cyber Security & Ethical Hacking (162)
  • Data Analytics (1,266)
  • Database (855)
  • Data Science (76)
  • DevOps & Agile (3,608)
  • Digital Marketing (111)
  • Events & Trending Topics (28)
  • IoT (Internet of Things) (387)
  • Java (1,247)
  • Kotlin (8)
  • Linux Administration (389)
  • Machine Learning (337)
  • MicroStrategy (6)
  • PMP (423)
  • Power BI (516)
  • Python (3,193)
  • RPA (650)
  • SalesForce (92)
  • Selenium (1,569)
  • Software Testing (56)
  • Tableau (608)
  • Talend (73)
  • TypeSript (124)
  • Web Development (3,002)
  • Ask us Anything! (66)
  • Others (2,231)
  • Mobile Development (395)
  • UI UX Design (24)

Join the world’s most active Tech Community!

Welcome back to the World’s most active Tech Community!

Subscribe to our Newsletter, and get personalized recommendations.

GoogleSign up with Google facebookSignup with Facebook

Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

  • DevOps Certification Training
  • AWS Architect Certification Training
  • Big Data Hadoop Certification Training
  • Tableau Training & Certification
  • Python Certification Training for Data Science
  • Selenium Certification Training
  • PMP® Certification Exam Training
  • Robotic Process Automation Training using UiPath
  • Apache Spark and Scala Certification Training
  • Microsoft Power BI Training
  • Online Java Course and Training
  • Python Certification Course
  • Data Scientist Masters Program
  • DevOps Engineer Masters Program
  • Cloud Architect Masters Program
  • Big Data Architect Masters Program
  • Machine Learning Engineer Masters Program
  • Full Stack Web Developer Masters Program
  • Business Intelligence Masters Program
  • Data Analyst Masters Program
  • Test Automation Engineer Masters Program
  • Post-Graduate Program in Artificial Intelligence & Machine Learning
  • Post-Graduate Program in Big Data Engineering

COMPANY

WORK WITH US

DOWNLOAD APP

appleplaystore googleplaystore

CATEGORIES

CATEGORIES

  • Cloud Computing
  • DevOps
  • Big Data
  • Data Science
  • BI and Visualization
  • Programming & Frameworks
  • Software Testing © 2023 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved. Terms & ConditionsLegal & Privacy

Источник

Оцените статью
Adblock
detector