Configure udev to change permissions on USB HID device?

I have a USB scale, a USB HID. Currently, when it is plugged in, the permissions only allow the superuser to access it. How can I configure udev to let anybody access this device? I have the vendor and product IDs, but I would like to match it based on the HID type instead.

Right now, I'm having trouble finding any existing rule that applies to this (I grepped for "hidraw" in /lib/udev/rules.d and /etc/udev/rules.d, among other things).


Solution 1:

Normally, this is done by adding to /etc/udev/rules.d a file maybe named 50-usb-scale.conf with contents like this:

SUBSYSTEM=="usb", ATTR{idVendor}=="HEX1", ATTR{idProduct}=="HEX2", MODE="0666"

Where HEX1 and HEX2 are replaced with the vendor and product id respectively.

To match on the Interface type instead, you could try replacing ATTR{idVendor}=="HEX1", ATTR{idProduct}=="HEX2" with a match for bInterfaceClass being 03 (HID):

SUBSYSTEM=="usb", ATTR{bInterfaceClass}=="03", MODE="0666"

But be warned, that will catch mice and keyboards too.

Solution 2:

Just for the summary:

You may filter for:

  • idVendor
  • idProduct
  • serial

And use:

== Compare for equality.

!= Compare for inequality.

= Assign a value to a key. Keys that represent a list are reset and only this single value is assigned.

+= Add the value to a key that holds a list of entries.

:= Assign a value to a key finally; disallow any later changes.

You may give a specific device a specific new path in /dev/...
Example:

KERNEL=="hiddev*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05df", ATTRS{serial}=="1234567", GROUP="cdrom", OWNER="user28", MODE="0640", SYMLINK+="myhid"

Results in:

You can access the device via '/dev/hiddevx' or via '/dev/myhid' easyly, every user in group 'cdrom' may read from the device. Owner 'user28' may read and write.

or simplest:

KERNEL=="hiddev*", ATTRS{idVendor}=="16c0", MODE="0666"

Results in: Every user may access every hiddevice from Vendor 0x16c0

For details see: Docs

Solution 3:

In case you need to change (like me) ttyACM0 permissions, this are my settings:

KERNEL=="ttyACM0", MODE="0777"

It failed when I tried to specify the vendor and product ID. I am not sure why.