Personal tools
You are here: Home documentation FAQ for Pd How can I set permissions to read HID devices on GNU/Linux?
Document Actions

How can I set permissions to read HID devices on GNU/Linux?

Up to Table of Contents

The Pd-extended [hid] object allows you to access Human Interface Devices such as mice, keyboards, and joysticks. However, in most Linux distributions, these devices are setup to where they cannot be read directly by Pd unless you run it as root.

Running a non-system process as root is considered a security risk, so an alternative is to change the permissions of the input devices so that pd can read them.

This guide has been tested on Ubuntu 9.10 Karmic. Please update and add an addendums for newer versions.

The fix is to write a udev rule opening permissions. Udev is a system daemon that creates the device tree in /dev as devices are added and removed based on a set of rules.

Following the Debian udev rules naming policy, create our rule for pd in /etc/udev/rules.d/85-pure-data.rules:

sudo mkdir -p /etc/udev/rules.d
sudo gedit /etc/udev/rules.d/85-pure-data.rules

Note: This is the Debian/Ubuntu location. Check your distribution for where it puts udev rules.

Now add the following rules to /etc/udev/rules.d/85-pure-data.rules:

#
#	pure data udev rules
#
#	Put me in "/etc/udev/rules.d", I am named based on the debian udev rules format
#
#	"add" actions are device insertions and device attributes are used to match the device
#
#	"remove" actions are matched using ENV variables since the SYSFS node for the device is gone
#	and thus the attributes have been deleted
#
#	rules built using:
#	- udevadm info -a -p $(udevadm info -q path -n /dev/*device*) : attributes
#	- sudo udevadm monitor --env /dev/*device* : events and env vars
#
#	Documentation is your friend: http://reactivated.net/writing_udev_rules.html
#
################################################################################################


#	input devices
#
SUBSYSTEM=="input", MODE="666"

Note: each udev rule must on a single line. Use only spaces, no tabs. Lines that start with `#` are comments.

This rule sets the permissions to 666 for input devices. Reboot your machine and the HID object should now be able to open them.

More Security

Setting input devices to 666 also opens the chance for someone to read your keyboard and mouse input. If you feel this is a security risk, try swapping MODE="666" with the following:

GROUP="input", MODE="660"
Then create an "input" group and add yourself to it:
sudo groupadd -f input
sudo gpasswd -a YOURUSERNAME input

This will add any input devices to the input group and only users you add to this this group can then read them. Reboot your machine for the rules to take effect.

Check

Check the permissions of the input devices:
$ ls -al /dev/input/
total 0
drwxr-xr-x  3 root root     220 2010-06-10 22:00 .
drwxr-xr-x 16 root root    3640 2010-06-10 22:00 ..
drwxr-xr-x  2 root root     100 2010-06-10 22:00 by-path
crw-rw----  1 root input 13, 64 2010-06-10 22:00 event0
crw-rw----  1 root input 13, 65 2010-06-10 22:00 event1
crw-rw----  1 root input 13, 66 2010-06-10 22:00 event2
crw-rw----  1 root input 13, 67 2010-06-10 22:00 event3
crw-rw----  1 root input 13, 68 2010-06-10 22:00 event4
crw-rw----  1 root input 13, 63 2010-06-10 22:00 mice
crw-rw----  1 root input 13, 32 2010-06-10 22:00 mouse0
crw-rw----  1 root input 13, 33 2010-06-10 22:00 mouse1

Here I used the more secure approach and you can see the event and mouse devices are marked rw for both users and groups.

Notes

If the rule dosen't seem to work, you can run a udev test to see if it's being read and if there are any errors. Run the test using an input device:

sudo udevadm test /dev/input/event0

Check out the udev tutorial on how to create more detailed rules. It's actually pretty easy once you get the hang of it. Mainly, use the following command to get a list of attributes to match to your target device wehn you plug it in or remove it, then use them to create a new rule:

udevadm info -a -p $(udevadm info -q path -n /dev/*your device*)

Links

by Dan Wilcox last modified 2013-10-18 11:37 PM

Powered by IEM Powered by Plone Section 508 WCAG Valid XHTML Valid CSS Usable in any browser