Joe Joe - 1 year ago 125
Linux Question

libusb calls without sudo using udev-rules

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download