Skip to content

Commit 914060b

Browse files
committed
Add simpler way to configure udev rules and ready to use udev rule file
It turns out that we can allow udev access to any USB hub using DRIVER=="hub" udev filter, this should make it easier for linux ditros to add proper udev rules. This change adds more documentation to README, and also adds ready to use udev rule that should work for any USB hub and any Linux kernel version.
1 parent 5a46019 commit 914060b

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,25 +222,25 @@ This is why there are additional rules for 6.0+ kernels.
222222
There is no harm in having these rules on systems running older kernel versions.
223223

224224
To fix USB permissions, first run `sudo uhubctl` and note all `vid:pid` for hubs you need to control.
225-
Then, add one or more udev rules like below to file `/etc/udev/rules.d/52-usb.rules` (replace 2001 with your vendor id):
225+
Then, add udev rules like below to file `/etc/udev/rules.d/52-usb.rules`
226+
(replace `2001` with your hub vendor id, or completely remove `ATTR{idVendor}` filter to allow any USB hub access):
226227

227-
SUBSYSTEM=="usb", ATTR{idVendor}=="2001", MODE="0666"
228-
229-
# Linux 6.0 or later (its ok to have this block present in older Linux):
228+
SUBSYSTEM=="usb", DRIVER=="hub", MODE="0666", ATTR{idVendor}=="2001"
229+
# Linux 6.0 or later (its ok to have this block present for older Linux kernels):
230230
SUBSYSTEM=="usb", DRIVER=="hub", \
231231
RUN="/bin/sh -c \"chmod -f 666 $sys$devpath/*-port*/disable || true\""
232232

233233
Note that for USB3 hubs, some hubs use different vendor ID for USB2 vs USB3 components of the same chip,
234-
and both need permissions to make uhubctl work properly. E.g. for Raspberry Pi 4B, you need to add these 2 lines:
234+
and both need permissions to make uhubctl work properly.
235+
E.g. for Raspberry Pi 4B, you need to add these 2 lines (or remove idVendor filter):
235236

236-
SUBSYSTEM=="usb", ATTR{idVendor}=="2109", MODE="0666"
237-
SUBSYSTEM=="usb", ATTR{idVendor}=="1d6b", MODE="0666"
237+
SUBSYSTEM=="usb", DRIVER=="hub", MODE="0666", ATTR{idVendor}=="2109"
238+
SUBSYSTEM=="usb", DRIVER=="hub", MODE="0666", ATTR{idVendor}=="1d6b"
238239

239240
If you don't like wide open mode `0666`, you can restrict access by group like this:
240241

241-
SUBSYSTEM=="usb", ATTR{idVendor}=="2001", MODE="0664", GROUP="dialout"
242-
243-
# Linux 6.0 or later (its ok to have this block present in older Linux):
242+
SUBSYSTEM=="usb", DRIVER=="hub", MODE="0664", GROUP="dialout"
243+
# Linux 6.0 or later (its ok to have this block present for older Linux kernels):
244244
SUBSYSTEM=="usb", DRIVER=="hub", \
245245
RUN+="/bin/sh -c \"chown -f root:dialout $sys$devpath/*-port*/disable || true\"" \
246246
RUN+="/bin/sh -c \"chmod -f 660 $sys$devpath/*-port*/disable || true\""
@@ -253,6 +253,7 @@ For your `udev` rule changes to take effect, reboot or run:
253253

254254
sudo udevadm trigger --attr-match=subsystem=usb
255255

256+
For your convenience, ready to use udev rule is provided [here](https://github.com/mvp/uhubctl/blob/master/udev/rules.d/52-usb.rules).
256257

257258

258259
FAQ

udev/rules.d/52-usb.rules

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# uhubctl – USB hub per-port power control https://github.com/mvp/uhubctl
2+
#
3+
# Copyright (c) 2009-2022, Vadim Mikhailov
4+
#
5+
# This file can be distributed under the terms and conditions of the
6+
# GNU General Public License version 2.
7+
8+
# uhubctl udev rules for rootless operation on Linux for users in group `dialout`.
9+
#
10+
# Copy this file to /etc/udev/rules.d, then reboot or run:
11+
#
12+
# sudo udevadm trigger --attr-match=subsystem=usb
13+
#
14+
# To add yourself to this permission group, run:
15+
#
16+
# sudo usermod -a -G dialout $USER
17+
18+
# This is for Linux before 6.0:
19+
SUBSYSTEM=="usb", DRIVER=="hub", MODE="0664", GROUP="dialout"
20+
21+
# This is for Linux 6.0 or later (ok to keep this block present for older Linux kernels):
22+
SUBSYSTEM=="usb", DRIVER=="hub", \
23+
RUN+="/bin/sh -c \"chown -f root:dialout $sys$devpath/*-port*/disable || true\"" \
24+
RUN+="/bin/sh -c \"chmod -f 660 $sys$devpath/*-port*/disable || true\""

0 commit comments

Comments
 (0)