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

Asked By: erjiang

||

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.

Answered By: Kees Cook

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.

Answered By: Rodo

If its a HIDRAW device, you have to

chmod 0666 /dev/hidrawX

where X is the hid device number, e.g hidraw0. you can do

ls /dev/hid*

to see a list 🙂
Or just do

sudo chmod 0666 /dev/hidraw*

to set for all hidraw devices, probably not recommended.

Answered By: Muriuki David

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

Answered By: rundekugel

Ubuntu 18.04 update/clarification:

Kees Cook’s answer is close but requires 2 changes to work in 18.04 (the current release and only one I’ve tested this on).

  1. Find your idVendor and idProduct with lsusb.
    • This will be the 2 hex values after “ID”, separated by a colon. I’m adding a scanner. lsusb gave me:
      Bus 001 Device 011: ID 04b8:014a Seiko Epson Corp. 
  2. As root add a file to /etc/udev/rules.d
    • Something like 50-usb-epsonscanner.rules
    • The extension must be “.rules”  
  3. In that file add:
    SUBSYSTEM=="usb", ATTRS{idVendor}=="04b8", ATTR{idProduct}=="014a", MODE="0666"

    But with your idVendor and idProduct hex values.

    • Note it’s “ATTRS” not “ATTR”.
  4. Re-login. No need to reboot.
Answered By: gatohaus

For a USB tty device, I needed to do:

SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE="0666", GROUP="bkg"

The accepted answer was good – but needed the SUBSYSTEM to be tty

The thing that helped be debug, was to be able to see what UDEV was doing by doing a:

udevadm test $(udevadm info -q path -n /dev/ttyUSB0)

Answered By: Brad
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.