# Linux Permissions

Note - this information applies to Ubuntu 10.04 and 12.04, and may or may not work for other versions.

Note 2 - as of version 1.4, a copy of 99-generichid.rules is now installed in the /etc/udev/rules.d directory.

When you insert a USB device, by default, the device is owned by root. A quick and dirty work-around is to run GenericHID as root but that will only allow the device to be built, and not run by the target application.

The correct solution is to create a udev rules file. A file is create in /etc/udev/rules.d which tells udev (the dynamic device management system) what to do when the device is inserted. These files are flexible, allowing other applications to be launched, but we only need to set permissions.

Permissions must be set for both the Generic HID device, and the DFU device (the device that appears when in programming mode).

Here is an example of a udev rules file. In my /etc/udev/rules.d/ folder I have created the file 99-generichid.rules. The name of the file is not important, as long as it has the extension .rules.

For Ubuntu 10.04...

> # Generic HID device
> SYSFS{idProduct}=="04d9", SYSFS{idVendor}=="1c40", MODE="0660", GROUP="plugdev"
> # Atmel DFU file for at90usb1286, at90usb1287
> SYSFS{idProduct}=="2ffb", SYSFS{idVendor}=="03eb", MODE="0660", GROUP="plugdev"

For Ubuntu 12.04...

> # Generic HID device
> ATTRS{idProduct}=="04d9", ATTRS{idVendor}=="1c40", MODE="0660", GROUP="plugdev"
> # Atmel DFU file for at90usb1286, at90usb1287
> ATTRS{idProduct}=="2ffb", ATTRS{idVendor}=="03eb", MODE="0660", GROUP="plugdev"

In my file, each data line has 4 parts. The first two specify the PID and VID of the USB device that this line applies to. The last 2 parts refer to the commands to run when a device is found. In this case, we set the permissions on the device to 0660 (owner=read/write, group=read/write), and we set the group of the device to plugdev.

The lines beginning with # are comments.

For this file to work, there must also be a group on the system called plugdev, and the user account that runs Generic HID and the application that uses the HID device must belong to this group. This can be done with the commands...

> sudo addgroup plugdev
> sudo addgroup myloginname plugdev

The rules file will take effect next time the device is plugged in.

There is more information about the rules file in udev(7) man page.