Skip to content

Commit fc8fdd2

Browse files
authored
improve documentation for udev rule files on Linux (libusb#276)
- use TAG+="uaccess" instead of overly broad MODE="0666" by default example as advised by Debian: https://lists.debian.org/debian-devel-announce/2016/11/msg00008.html Adding the uaccess tag to udev rules ------------------------------------ Packages containing udev rules that use GROUP="plugdev" should also add TAG+="uaccess" so that all users that are physically present can access the relevant devices, instead of just users in the plugdev group (GROUP="plugdev"). Some packages use MODE="666" to allow all users (including remote users) to access devices. For almost all devices it is probably more appropriate to switch from MODE="666" to GROUP="plugdev", MODE="660", TAG+="uaccess" so that remote users cannot access local devices. Check the wiki page for USB gadgets[13] for more hints. There is a lintian warning in progress[14] for these issues. -- Paul Wise & Petter Reinholdtsen [] https://wiki.debian.org/USB/GadgetSetup [] https://bugs.debian.org/841670 - remove documentation for Linux <2.6.24
1 parent c13fb1a commit fc8fdd2

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ built by default. It is up to the application linking to hidapi to choose
5050
the backend at link time by linking to either `libhidapi-libusb` or
5151
`libhidapi-hidraw`.
5252

53+
Note that you will need to install a udev rule file with your application
54+
for unprivileged users to be able to access HID devices with hidapi. Refer
55+
to the [69-hid-udev.rules](udev/69-hid-udev.rules) file in the `udev` directory
56+
for an example.
57+
5358
__Linux/hidraw__ (`linux/hid.c`):
5459

5560
This back-end uses the hidraw interface in the Linux kernel, and supports

udev/69-hid.rules

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This is a sample udev file for HIDAPI devices which lets unprivileged
2+
# users who are physically present at the system (not remote users) access
3+
# HID devices.
4+
5+
# If you are using the libusb implementation of hidapi (libusb/hid.c), then
6+
# use something like the following line, substituting the VID and PID with
7+
# those of your device.
8+
9+
# HIDAPI/libusb
10+
SUBSYSTEM=="usb", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="003f", TAG+="uaccess"
11+
12+
# If you are using the hidraw implementation (linux/hid.c), then do something
13+
# like the following, substituting the VID and PID with your device.
14+
15+
# HIDAPI/hidraw
16+
KERNEL=="hidraw*", ATTRS{idVendor}=="04d8", ATTRS{idProduct}=="003f", TAG+="uaccess"
17+
18+
# Once done, optionally rename this file for your application, and drop it into
19+
# /etc/udev/rules.d. Note that these rules must have priorty before 70-uaccess.rules
20+
# for example, name the file /etc/udev/rules.d/69-my-application-hid.rules.
21+
# Then, replug your device or run:
22+
# sudo udevadm control --reload-rules && sudo udevadm trigger
23+
24+
# Note that the hexadecimal values for VID and PID are case sensitive and
25+
# must be lower case.
26+
27+
# TAG+="uaccess" only gives permission to physically present users, which
28+
# is appropriate in most scenarios. If you require remote access to the
29+
# device, add
30+
# GROUP="plugdev", MODE="660"
31+
# to the end of the udev rule lines, add your user to the plugdev group with:
32+
# usermod -aG plugdev USERNAME
33+
# then log out and log back in (or restart the system).

udev/99-hid.rules

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)