Skip to content

Instantly share code, notes, and snippets.

@flug
Last active September 15, 2017 09:46
Show Gist options
  • Select an option

  • Save flug/a67327e77cf82328eb18a35221426e81 to your computer and use it in GitHub Desktop.

Select an option

Save flug/a67327e77cf82328eb18a35221426e81 to your computer and use it in GitHub Desktop.
Lock and unlock session linux with usb key

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>*

cuttlefish could be one solution to do it as @maythux suggested. I really can't comment on its capabilities, I prefer to stay away from 3rd party apps as much as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment