3

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?

  • 1
    IMHO udev is frustratingly opaque and poorly documented: I think you may need to use attribute SUBSYSTEMS (plural) rather than SUBSYSTEM (singular). Someone might be able to give a better analysis if you edit your question to include the output of udevadm info --attribute-walk /dev/xxx where /dev/xxx is the actual devpath of your device. – steeldriver Mar 12 '15 at 12:15
  • @steeldriver: I don't see my device having a /dev/ entry, so I don't know how to invoke udevadm on it. All I have is bus, dev. number, VID and PID as shown by lsusb (and name). – Violet Giraffe Mar 12 '15 at 12:55
  • @steeldriver: SUBSYSTEMS instead of SUBSYSTEM seems to make no difference at all. – Violet Giraffe Mar 12 '15 at 13:00
1

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
1

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.

  • I'll have to find out what a group is, but thanks :) – Violet Giraffe Jun 30 '17 at 8:11
  • Every linux user is a member of at least one, and possibly more groups. So if for instance your username was violetg you could do: sudo usermod -a -G plugdev violetg to add yourself to the plugdev group, which would in turn give you access to usb devices (after logging out and back in again). – Justin Buser Jul 13 '17 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.