3

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"
Joe
  • 3,090
  • 6
  • 37
  • 55

3 Answers3

8

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.

David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • as I understand, the `MODE=` just changes the permissions of the `/dev/ttyACM…` file but not those of the entries in `/dev/bus/usb/…` – Joe Nov 14 '16 at 22:02
  • In the Unix world, "mode" is general term used and it refers to file permissions. It does not refer to ACM devices. I have used rules like this successfully with libusb before. Did you try my rule? – David Grayson Nov 14 '16 at 22:18
  • Yeah, `SUBSYSTEM=="usb"` was the trick to make the following `MODE=…` and `GROUP=…` affect to `/dev/bus/usb/…`. Until before, I'd just used `SUBSYSTEM=="tty"`. – Joe Nov 14 '16 at 23:44
1

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.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Did you replug the device? – Ignacio Vazquez-Abrams Nov 14 '16 at 21:16
  • Yep, and als also added a `RUN+="…"` to make sure that the rule will be executed. Btw: IMHO the `ID_MM_DEVICE_IGNORE` is not longer required in 16.04, isn't it (I know such modem manager trouble from 14.04)? – Joe Nov 14 '16 at 21:18
  • adding `GROUP="plugdev"` seems also to change nothing – Joe Nov 14 '16 at 21:19
  • correction of the above comment: adding `GROUP="plugdev"` just changes the group of `/dev/ttyACM*` but not of `/dev/bus/usb/…`. – Joe Nov 14 '16 at 22:00
0

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.

sopel
  • 61
  • 2