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?
-
You should clarify what purpose you have for wanting the pi user to have write permission on dev nodes, or else this just reads like something someone might say if they were just learning linux but did not really understand what a dev node is about. To clarify: there might be some legitimate reason for doing this, but in general there is not, so either you need an answer that explains why there is not, or else an answer that explains how to do what you want (but for that, you need to explain what it is you want to do). So, save everyone some time, "I didn't mean that", etc, and clarify. – goldilocks Mar 06 '13 at 01:49
-
Sorry, I thought it was self evident; all of the programming examples that do i/o with the pins are run with sudo. I'd rather run them as the pi user and not root. – lumpynose Mar 06 '13 at 03:32
-
Okay. I've added an answer then ;) – goldilocks Mar 06 '13 at 13:22
2 Answers
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.

- 58,859
- 17
- 112
- 227
-
-
1Awesome! For others stumbling, the command might be something else to add a group. For arch linux, it turned out to be groupadd. Just check your distro docs. – Hendy Jan 04 '18 at 01:36
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.

- 101
- 2