Lock and Unlock from USB disk (pendrive)
Solution 1:
I know it's a terribly late answer, just thought it might help future readers. I posted the answer at Locking with USB drive
Well, a module called PAM (Pluggable Authentication module) can be customized to achieve your need. A beautiful article is available on linuxconfig describing this in detail.
The steps are:
-
Install PAM
$ sudo apt-get install pamusb-tools libpam-usb
-
Add USB device to PAM config
$ sudo pamusb-conf --add-device <my-usb-stick>
Select your volume and "Y" to save
-
Define user for PAM auth
$ sudo pamusb-conf --add-user <ubuntu-user>
Select and "Y" to save
-
Configure PAM
$ sudo gedit /etc/pam.d/common-auth
-
Add the line below and save
auth sufficient pam_usb.so
-
Test the PAM auth
$ su ubuntu-user
-
Lock when disconnected
$ sudo gedit /etc/pamusb.conf
-
Modify the block "user" block to look like:
<user id="ubuntu-user"> <device> my-usb-stick </device> <agent event="lock">gnome-screensaver-command -l</agent> <agent event="unlock">gnome-screensaver-command -d</agent> </user>*
Solution 2:
In
/etc/udev/rules.d/
you can write a script
SUBSYSTEM=="usb", SYSFS{idProduct}=="PPPP", SYSFS{idVendor}=="VVVV", RUN+="/usr/sbin/usb-locking"
where PPPP and VVVV are values you can extract with lsusb
.
Every identic product will match, but usb-locking could mount the device, and look at the drive itself for further legitimation - some file, some bytecode in there, the date ...
It's vulnerable if somebody else get's access to the stick, of course.
The script could further look every minute, whether the stick is still mounted, and lock if not.
Solution 3:
Thanks for your suggestion.. I wrote a simple script utilizing the lsusb command and put in system -> preferences-> startup applications. The script is as follows..
#!/bin/sh # Script to automatically lock and unlock the computer when my usb pendrive is removed LSUSB=`which lsusb` if [ -z $LSUSB ]; then echo "No lsusb command found. exiting.. \n" exit 56 fi while : do sleep 3 echo "Running in loop" # Check the USB drive USB=`lsusb | grep Logitech` if [ -n "${USB}" ] ; then echo "USB Device: Transcend found" # find and kill any screensaver found. gnome-screensaver-command --deactivate continue fi # USB Device Not Found # Check if screensaver is running or not # if not running then start screensaver gnome-screensaver-command --activate done exit 0