libusb calls without sudo using udev-rules

99封情书 提交于 2020-04-30 05:11:11

问题


Tested on Kubuntu 16.04 64 bit only. I have an application which source is not under my control. It uses some libusb calls which ends up in e.g.:

libusb: error [_get_usbfs_fd] libusb couldn't open USB device /dev/bus/usb/001/031: Permission denied
libusb: error [_get_usbfs_fd] libusb requires write access to USB device nodes.                                   

When running the above mentioned application as root, it works as expected. When I change the permissions of the regarding file like:

sudo chmod a+w /dev/bus/usb/001/031

then the application will work with standard user rights (until I disconnect / reconnect my usb device).

Now I'm looking for a way, to e.g. automatically execute the chmod a+w each time when the specific usb device is plugged in. Might this be possible by writing a specific udev rule?

Maybe other solutions the libusb calls without root rights?

Solution: Based upon David Grayson's answer, I'd now added an additional line with SUBSYSTEM=="usb" to my rule file. My rules file now finally looks like this:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="1234", ATTRS{idProduct}=="5678", MODE="0666"

回答1:


I suggest that you add a new file in /etc/udev/rules.d named usb.rules. It should have the following contents:

SUBSYSTEM=="usb", MODE="0666"

This will make all USB devices readable and writable by all users.

You could also narrow it down to specific USB devices using idVendor and idProduct attributes mentioned in Ignacio's answer.




回答2:


Assuming Kubuntu 16.04 uses PolicyKit, put the following in a file in /etc/udev/rules.d, naming it similarly to the files that already exist there:

ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", TAG+="uaccess", ENV{ID_MM_DEVICE_IGNORE}="1"

Replace the two sets of "xxxx" with the vendor ID and product ID of the device respectively.



来源:https://stackoverflow.com/questions/40597515/libusb-calls-without-sudo-using-udev-rules

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