I have a USB key that contains my keepass2 password database and I'd like to perform some actions when it is plugged into my computer, namely:

  • Auto-mount it to some specific location
  • When the mounting is done properly, launching keepass2 on the password database file

Simple tasks I guess, but I can't find how to do that.

I'm using Ubuntu 12.10, and it auto-mounts the device as a "media usb-key" and tries to open the images on it (even though there are none).

What is the best way to do that and to disable the ubuntu auto-mounting (so it doesn't conflict) ?


You can do this with udev, you must write rules in separate file and put them to /etc/udev/rules.d

For example this rule describes udev to run /path/to/mount/script when usb is mounted and /path/to/umount/script when umounted.

SUBSYSTEMS=="usb", ACTION=="add", KERNEL=="sd[a-z]1", RUN+="/path/to/mount/script", OPTIONS="last_rule"
SUBSYSTEMS=="usb", ACTION=="remove", KERNEL=="sd[a-z]1", RUN+="/path/to/umount/script"

Here you can read complete manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.