How to allow software access to any USB devices?

28,284

Solution 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.

Solution 2

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
Share:
28,284

Related videos on Youtube

Violet Giraffe
Author by

Violet Giraffe

I'm from Kharkiv, Ukraine. My city is being destroyed every day. Help us defend: https://savelife.in.ua/en/donate/ PC enthusiast, C++ fan and C++ / Qt / Android software developer. Also &lt;3 Arduino. Music and car addict. Reinventing various wheels in my spare time. A custom-made square wheel is like a tailored suit, wouldn't you agree? Why do I have more rep from questions than from answers? Because you don't learn by answering; you learn by asking questions :) Ongoing personal open-source projects: Dual-panel file manager for Windows / Linux / Mac

Updated on September 18, 2022

Comments

  • Violet Giraffe
    Violet Giraffe over 1 year

    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?

  • Violet Giraffe
    Violet Giraffe almost 7 years
    I'll have to find out what a group is, but thanks :)
  • Justin Buser
    Justin Buser almost 7 years
    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).