Is it possible to have a USB drive function as a login token?

IE: I turn on my computer, plug the USB drive into my system and the system recognises it and logs me in? Likewise, logs me out should the drive be removed?

Thanks in advance :)


There is an article at LinuxConfig for Linux authentication login with USB device.

accomplished by use of Pluggable Authentication Modules ( PAM ) and some sort of USB storage device such as USB memory stick of Mobile phone with SD card attached.

This authentication technique can be also further expanded into Two-Factor authentication where two authentication methods involving USB token and one-time password can be merged together to produce a greater security.

A summary of actions,

  1. sudo apt-get install pamusb-tools libpam-usb
  2. sudo pamusb-conf --add-device my-usb-stick
  3. sudo pamusb-conf --add-user ubuntu-user
  4. edit a /etc/pam.d/common-auth file
    • auth sufficient pam_usb.so
    • auth required pam_unix.so nullok_secure
    • Before you do any changes to /etc/pam.d/common-auth open-up separate terminal with root access. This is just in case that something goes wrong, and you need a root access to change /etc/pam.d/common-auth back to the original configuration.
  5. su ubuntu-user -- "ubuntu-user" is the username from step 3.
  6. There are some more notes at the end
  • Thank you, that was what I was (almost) looking for. Now, if only someone could write a GUI to make the process a little less terminal-mad :P – Dante Ashton Nov 1 '10 at 21:02
  • 1
    The packages pamusb-tools and libpam-usb are no longer included in Ubuntu 16.04. Any ideas? – e18r May 6 '17 at 4:24

It's not a regular USB key, but have you looked at YubiKey? It can generate either one-time passwords or just send a normal but long password, and it's recognised as a USB keyboard so it works on pretty much any computer.

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.