10

I found a strange thing while playing with pi3B. I want to create a file in /sys/class/gpio (just poking around, no specific reason) but I get a Permission Denied. Below is some information.

pi@raspberrypi:/sys/class/gpio $ groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev gpio i2c spi
pi@raspberrypi:/sys/class/gpio $ ls -ld .
drwxrwx--- 2 root gpio 0 May  6 00:28 .
pi@raspberrypi:/sys/class/gpio $ touch somefile
touch: cannot touch 'somefile': Permission denied

As you can see, I am in group gpio and the group has the write permission of directory /sys/class/gpio.

So the question is Why I can't create new files in /sys/class/gpio even if the group I am a part of has the permission.

I tried relogin and reboot after add the pi user to group gpio and that's several days ago.

OS: raspbian stretch

tried newgrp newgrp

  • Have you try with newgrp gpio command (and then touch ...)? – Romeo Ninov May 6 '18 at 7:40
  • @RomeoNinov just tried, see Edit. – Charles May 6 '18 at 7:50
  • 1
    We see that. But you have posted an image. Please avoid that and post text version whenever available. – LinuxSecurityFreak May 6 '18 at 7:51
  • @Vlastimil OK I will pay attention to that next time(original text is gone now). thx. – Charles May 6 '18 at 7:55
19

/sys directory is special. You can't just poke around and create files

Wikipedia excerpt:

Modern Linux distributions include a /sys directory as a virtual filesystem (sysfs, comparable to /proc, which is a procfs), which stores and allows modification of the devices connected to the system, whereas many traditional UNIX and Unix-like operating systems use /sys as a symbolic link to the kernel source tree.

Entries in /sys are created by the kernel and by drivers; you cannot just create them from the command-line. You might edit some as root, but you cannot generally make new ones from userspace except by loading kernel modules or otherwise installing drivers or modifying the kernel.

  • Just noticed that I cannot create files even when I am root. That explains a lot. Thanks. – Charles May 6 '18 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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