How to allow software access to any USB devices?

I have a libusb-based program that can't open USB devices on a freshly installed Ubuntu because it lacks permissions.

This solution will probably work for me, but it requires manually specifying each and every device - and I have quite a few. So I tried this (in a file /etc/udev/rules.d/41-cvs-permissions.rules):

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

I've omitted VID and PID, hoping that it will simply apply the rule to ALL devices. It definitely has some effect, but the effect is rather weird: instead of detecting 5 devices that it can't open, libusb only detects 2 now - both are USB host controllers, not actual devices.

How to achieve what I want?


I agree that making rule match using VID/PID is not a definite solution. But you can much multiple devices in same rule without targeting blindly all USB devices the way you did. Example using DRIVER name (usb-storage, usbhid,..) or KERNEL name (tty*, sd*,..) even using minimal regex (sd[a-z][0-9]*, usb*).

You should look for similarities in their attributes.

  1. Remove all those devices
  2. Save the current list of devices in /dev

    ls /dev > /tmp/dev_list0.txt
    
  3. Plug one of the target devices

  4. Save the list of devices in another file

    ls /dev > /tmp/dev_list.txt
    
  5. Compare files, > added device, < removed device

    $ colordiff /tmp/dev_list0.txt /tmp/dev_list.txt
    85a86,87
    > sdc
    > serial
    89a92,93
    > sg4
    > sg5
    93a98
    > sr1
    194a200,201
    > ttyUSB0
    > ttyUSB1
    

    This is a 3G modem.

  6. Check the attribute for all interfaces you need, example:

    udevadm info --attribute-walk --name=/dev/ttyUSB0
    

Do the same for all devices you want. If you can't figure out how, please upload their udevadm info --attribute-walk --name=... output and link them to your question.

Note that, not all USB devices create a node in /dev. Some you have look for them in SYSFS tree /sys. Then check their attributes using --path

udevadm info --attribute-walk --path=...

Using same steps as above you can check which device nodes created by monitoring udev events:

udevadm monitor

The way I deal with USB devices is to give a specific group access to all of them.

As root:

echo 'SUBSYSTEM=="usb", MODE="0660", GROUP="plugdev"' > /etc/udev/rules.d/00-usb-permissions.rules
udevadm control --reload-rules

Essentially what this does is grant read and write access for any usb device to members of the plugdev group.