我有USB設備,USB HID。目前,當插入時,權限僅允許超級用戶訪問它。如何配置udev讓任何人訪問此設備?我有供應商和產品ID,但我想基於HID類型匹配它。
通常,這是通過添加到/etc/udev/rules.d
可能以這樣99-hid.rules
的內容命名的文件來完成的:
SUBSYSTEM=="usb", ATTR{idVendor}=="HEX1", ATTR{idProduct}=="HEX2", MODE="0666"
其中HEX1和HEX2分別替換爲供應商和產品ID。
要匹配的接口類型,而不是,你可以嘗試更換ATTR{idVendor}=="HEX1", ATTR{idProduct}=="HEX2"
一個匹配的bInterfaceClass
是03
(HID):
SUBSYSTEM=="usb", ATTR{bInterfaceClass}=="03", MODE="0666"
但要注意,這也將捕捉鼠標和鍵盤。
例程文件如下:
# This is a sample udev file for HIDAPI devices which changes the permissions
# to 0666 (world readable/writable) for a specified device on Linux systems.
# If you are using the libusb implementation of hidapi (libusb/hid.c), then
# use something like the following line, substituting the VID and PID with
# those of your device. Note that for kernels before 2.6.24, you will need
# to substitute "usb" with "usb_device". It shouldn't hurt to use two lines
# (one each way) for compatibility with older systems.
# HIDAPI/libusb
SUBSYSTEM=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5720", MODE="0666"
# If you are using the hidraw implementation (linux/hid.c), then do something
# like the following, substituting the VID and PID with your device. Busnum 1
# is USB.
# HIDAPI/hidraw
KERNEL=="hidraw*", ATTRS{busnum}=="1", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5720", MODE="0666"
# Once done, optionally rename this file for your device, and drop it into
# /etc/udev/rules.d and unplug and re-plug your device. This is all that is
# necessary to see the new permissions. Udev does not have to be restarted.
# Note that the hexadecimal values for VID and PID are case sensitive and
# must be lower case.
# If you think permissions of 0666 are too loose, then see:
# http://reactivated.net/writing_udev_rules.html for more information on finer
# grained permission setting. For example, it might be sufficient to just
# set the group or user owner for specific devices (for example the plugdev
# group on some systems).