Permission denied for some files, even with sudo and chmod 777
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, but this is a different problem.)
The most common way to access such files is to use a root shell:
sudo -i