OK, I got a set of YubiKey‘s some time ago and I use one to supplement my Linux desktop login. But I wanted to lock my screen automatically when I remove my YubiKey-Nano. So I wrote a little Python daemon which is auto-started on login and watches for USB remove events. Once the USB-subsystem reports that `any’ YubiKey is removed, the screen is locked. Maybe you spotted the little problem here, the USB stuff does not know which key was removed. But since I don’t think I’ll let too many other keys connect to my laptop, it is only a little problem;-)
My little program is here: yubikey-notify.py
I’m using KDE, so for me, I dropped this into ~/.kde/Autostart/yubikey-notify.py , just make sure it’s executable by the user;-) But other desktop environments should have a similar location.
This little program can easily be modified to do other things triggered by USB (or other) udev events.
As always, have fun,
— Marco