Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've had multiple times that I wasn't allowed to edit a file. Even when I chmoded to 777 and opend the file with sudo. E.g. the file /sys/kernel/debug/vgaswitcheroo/switch in this tutorial.

First, how is this possible? Second, how can I get access to this sort of files?

share|improve this question
add comment

2 Answers

It is not enough to have read permission on a file in order to read it. You also need to have read permission on the directory it belongs to. In the case of /sys/kernel/debug/vgaswitcheroo/switch the problem is /sys/kernel/debug which, by default, is readable only by root:

$ ls -ld /sys/kernel/debug
drwx------ 22 root root 0 Nov 20 18:25 /sys/kernel/debug

You need to chmod a+r /sys/kernel/debug to have access to the contents of that directory. (I would not recommend it, since giving global access to /sys/kernel/debug is not a safe thing to do, however this has nothing to do with your question)

The most common way to access such files is to use a root shell:

sudo -i
share|improve this answer
add comment

what ever the file it is, you can have the access to it with sudo .

for example In GUI

sudo gedit <path-to-file-name>

In CLI

sudo nano <path to file name>
share|improve this answer
    
not true askubuntu.com/questions/279853/… –  maazza Apr 10 '13 at 10:21
    
also on some systems u get permission denied on /etc/sudoers, instead u use sudo visudo –  Moataz Elmasry Nov 15 '13 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.