changed:
-
<h2>Background</h2>
<p>The 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.</p>
<p>Running 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.</p>
<p>This guide has been tested on Ubuntu 9.10 Karmic. Please update and add an addendums for newer versions.</p>
<h2>How To</h2>
<p>The fix is to write a udev rule opening permissions. <a href="http://en.wikipedia.org/wiki/Udev">Udev</a> is a system daemon that creates the device tree in /dev as devices are added and removed based on a set of rules.</p>
<p>Following the <a href="http://demo.dersbach.ch/cgi-bin/dwww/usr/share/doc/udev/README.Debian.gz">Debian udev rules naming policy</a>, create our rule for pd in /etc/udev/rules.d/85-pure-data.rules:</p>
<pre>
sudo mkdir -p /etc/udev/rules.d
sudo gedit /etc/udev/rules.d/85-pure-data.rules
</pre>
<p>Note: This is the Debian/Ubuntu location. Check your distribution for where it puts udev rules.</p>
<p>Now add the following rules to /etc/udev/rules.d/85-pure-data.rules:</p>
<pre>
#
# 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"
</pre>
<p>Note: each udev rule <b>must</b> on a single line. Use only spaces, no tabs.</p>
<p>This rule sets the permissions to 666 for input devices. Reboot your machine and the HID object should now be able to open them.<p>
<h3>More Security</h3>
<p>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 <code>MODE="666"</code> with the following:</p>
<pre>
GROUP="input", MODE="660"
</pre>
Then create an "input" group and add yourself to it:
<pre>
sudo groupadd -f input
sudo gpasswd -a YOURUSERNAME input
</pre>
<p>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. </p>
<h3>Check</h3>
Check the permissions of the input devices:
<pre>
$ 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
</pre>
<p>Here I used the more secure approach and you can see the event and mouse devices are marked rw for both users and groups.</p>
<h2>Notes</h2>
<p>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:</p>
<pre>sudo udevadm test /dev/input/event0</pre>
<p>Check out the <a href="http://reactivated.net/writing_udev_rules.html">udev tutorial</a> 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:</p>
<pre>udevadm info -a -p $(udevadm info -q path -n /dev/*your device*)</pre>
<h3>Links</h3>
<ul>
<li><a href="http://reactivated.net/writing_udev_rules.html">Udev Tutorial</a></li>
<li><a href="http://sourceforge.net/apps/mediawiki/gizmod/index.php?title=HOWTO_-_Setting_Input_Device_Permissions_-_Creating_a_udev_Rule">Setting Input Device Permissions</a></li>
</ul>