Get access to USB device on Linux (libusb-1.0)?

自古美人都是妖i 提交于 2019-12-10 02:37:39

问题


I am writing a small program to communicate with a specific USB HID product (identified by vendor and product IDs), using libusb-1.0 on Linux. Right now, I have to run the program as root because "libusb requires write access to USB device nodes". Is there a way to change the permissions on the device I need so that I don't need to run my program as root?


回答1:


On modern Linux systems, udevd (man 7 udev) creates the device nodes for USB devices when they're plugged in. Add a udev rule that matches your device (eg. you could match by USB Vendor and Product IDs), and sets the OWNER / GROUP / MODE of the device node.

The best approach is probably to create a new group for users who should be able to access the device, then set that as the group owner in the udev rule. You may also need to use MODE to ensure that it has group read/write permissions. Eg. your rule will probably look something like:

SUBSYSTEMS=="usb", ATTRS{idVendor}=="ffee", ATTRS{idProduct}=="5a5a", MODE="0660", GROUP="foobar"


来源:https://stackoverflow.com/questions/4300837/get-access-to-usb-device-on-linux-libusb-1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!