From Peter Kropf:

 Setting up Hotplug for USB access


There are times when access to the 1-Wire USB controller has to be
modified to allow a user other than root to have write access. This
article presents a simple way to use the Linux Hotplug subsystem to
change the file ownership and permissions on the file associated with
a 1-Wire controller.

Linux Hotplug Subsystem

The notes presented here are specific to the Linux Hotplug subsystem
and it must be installed for it to work. To install it on a Debian
based system:

apt-get install hotplug

If you're running a version of Linux other than Debian, see the
documentation for that version Linux for more details on how to
install the Hotplug subsystem.

USB Vendor and Product IDs

The USB vendor and product ids are used by the Hotplug subsystem to
identify which program is to be run when the device is plugged in.

If you don't know the vendor and product ids for the 1-Wire USB
controller you'll be using, you can use the lsusb program to find
them. If lsusb isn't installed (typically in /usr/sbin) you'll need to
install the appropiate package for your Linux distribution. On Debian
systems, that means installing the usbutils package.

apt-get install usbutils

Once installed, run lsusb with the 1-Wire USB controlled plugged in:

$ /usr/sbin/lsusb
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 013: ID 04fa:2490 Dallas Semiconductor DS1490F 2-in-1 Fob, 1-Wire adapter
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

The 04fa is the vendor id and 2490 is the product id.

Unplug the 1-Wire USB controller.

Customize Hotplug

With the vendor and product ids in hand, the Hotplug subsystem can be
modified to change the file permissions and file ownership.

Create a new file called /etc/hotplug/usb/ow.usermap. This will
contain the mapping of vendor / product id and the program to run. The
file should contain a single line that looks like:

ow 0x03 0x04fa 0x2490 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000

Change the 0x04fa to the vendor id and 0x2490 to the product id for
your 1-Wire USB controller.

Create a new shell program called /etc/hotplug/usb/ow. This will be
the program that is run. Here's a simple example of changing the file
group to ow and giving the group read and write access.

#! /bin/sh

if [ "$DEVICE" != "" ]; then
# we have a device so setup security
chgrp ow $DEVICE && chmod g+rw $DEVICE && logger "ow hotplug: group set to ow and permission g+rw on $DEVICE"
logger "ow hotplug: error - no device"

The file has to be made executable via

chmod +x /etc/hotplug/usb/ow

otherwise it will not be excuted by the Hotplug subsystem.

Also, don't forget to add a group called ow and add users to the group.

Once this is setup, you can plug the 1-Wire USB controller into the
computer. After a bit, you should see a message in the system log file
that looks like:

Nov 29 10:06:27 kuro2 logger: ow hotplug: group set to ow and permission g+rw on /proc/bus/usb/002/013

and that can be verified by

$ ls -l /proc/bus/usb/002/013
-rw-rw-r-- 1 root ow 147 Nov 29 10:06 /proc/bus/usb/002/013


Previous page: Permissions
Next page: Fuse permissions