7

I'm waiting for my Pi. From reading the tutorials and books on doing i/o on the Pi I'm getting the impression that linux makes entries in /dev on the fly, which is nice, but they're owned by someone other than the pi user. Is there a way to have Linux make the /dev entries world writable or owned by pi?

Ghanima
  • 15,958
  • 17
  • 65
  • 125
lumpynose
  • 291
  • 2
  • 7

3 Answers3

12

You can change the permissions on a device node using chmod, eg:

chmod g+rw /dev/whatever

This adds read/write permissions for the group owning 'whatever'. A lot of stuff in /dev is uid and gid 0 (owner root, group root) but some things have a separate group such as 'video' or 'disk', and when this is the case, the group will already have read write permissions on the node. So, first check if the node you are interested in is like that:

stat -c "%A %G" /dev/whatever

If so, just add the pi user to that group. If the group is called "mydevice":

usermod -a -G mydevice pi

Done. If the node does not belong to a special group, you can create one:

addgroup mydevice

Note on some distros this command is groupadd. Now chown the device to that group and tweak the permissions:

chown root.mydevice /dev/whatever
chmod g+rw /dev/whatever

Then add the pi user to the group. The new group, and the pi user's membership in it, are permanent (until you change them again). However, the dev nodes are actually created at boot, so any changes you make to them will not persist. You can make that permanent by adding a udev rule. Create a text file in /etc/udev/rules.d called mydevice.rules (or anything with the suffix .rules) and add a rule:

KERNEL=="whatever", NAME="%k", GROUP="mydevice", MODE="0660"

Beware the difference between == and = there. Here's a (slightly aged) guide to udev rules, most of which still seems to be valid.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
0

I would like to access gpiomem in my python script without the need to run my script with sudo every time. ls -al /dev/gpiomem tells me that this belongs to owner root and group root with rw access only to the owner. I can do this temporarily by giving rw access using chmod but this only works until the next reboot.

I followed the above instructions creating a .rules file which I hope would permanently resolve this issue but no such luck.

What an I missing please?

xuraax
  • 1
  • 1
0

In the latest Jessie the group that user needs to be part of is gpio, so sudo usermod -a -G gpio <user name> did the magic for me.

Adarsha
  • 101
  • 2