Joe
Joe

Reputation: 3160

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?

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"

Upvotes: 3

Views: 7340

Answers (3)

sopel
sopel

Reputation: 61

Oldie but goldie. Help me to solve my issue with sharing the usb with virtual machines under AQEMU. Thanks a lot. I added to the /etc/udev/rules.d file usb.rules with this line

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

and virtual machine can see USB stick being connected life.

Upvotes: 0

David Grayson
David Grayson

Reputation: 87476

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.

Upvotes: 8

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799044

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.

Upvotes: 1

Related Questions