Hardware authentication for Linux using ordinary USB Flash Drives.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

247 lines
8.2 KiB

12 years ago
13 years ago
12 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. pam\_usb
  2. ========
  3. pam\_usb provides hardware authentication for Linux using ordinary USB Flash Drives.
  4. It works with any application supporting PAM, such as _su_ and login managers (_GDM_, _KDM_).
  5. Features
  6. --------
  7. * `Password-less authentication.` Use your USB stick for authentication, don't type passwords anymore.
  8. * `Device auto probing.` You don't need to mount the device, or even to configure the device location (_sda1_, _sdb1_, etc). pam\_usb.so will automatically locate the device using _HAL_ and access its data by itself.
  9. * `Two-factor authentication.` Achieve greater security by requiring both the USB stick and the password to authenticate the user.
  10. * `Non-intrusive.` pam\_usb doesn't require any modifications of the USB storage device to work (no additional partitions required).
  11. * USB Serial number, model and vendor verification.
  12. * Support for **One Time Pads** authentication.
  13. * You can use the same device accross multiple machines.
  14. * Support for all kind of removable devices (SD, MMC, etc).
  15. Tools
  16. -----
  17. * `pamusb-agent`: trigger actions (such as locking the screen) upon device authentication and removal.
  18. * `pamusb-conf`: configuration helper.
  19. * `pamusb-check`: integrate pam\_usb's authentication engine within your scripts or applications.
  20. Installing
  21. ==========
  22. pam_usb is included in most Linux distributions out there.
  23. If you happen to run Ubuntu or Debian, run:
  24. # apt-get install libpam-usb pamusb-tools
  25. Compiling from source
  26. ---------------------
  27. Before proceeding, make sure all dependencies are installed: libxml2, pam, udisks and pmount are installed
  28. $ make
  29. # make install
  30. Configuring
  31. ===========
  32. By default, pam_usb will read its configuration from `/etc/pamusb.conf`
  33. For most operations, you can use ``pamusb-conf`` which will take care of generating the configuration for you.
  34. Setting up Devices and Users
  35. ----------------------------
  36. Once you've connected your USB device to the computer, use pamusb-conf to add it to the configuration file:
  37. # pamusb-conf --add-device MyDevice
  38. Please select the device you wish to add.
  39. * Using "SanDisk Corp. Cruzer Titanium (SNDKXXXXXXXXXXXXXXXX)" (only option)
  40. Which volume would you like to use for storing data ?
  41. * Using "/dev/sda1 (UUID: <6F6B-42FC>)" (only option)
  42. Name : MyDevice
  43. Vendor : SanDisk Corp.
  44. Model : Cruzer Titanium
  45. Serial : SNDKXXXXXXXXXXXXXXXX
  46. Volume UUID : 6F6B-42FC (/dev/sda1)
  47. Save to /etc/pamusb.conf ?
  48. [Y/n] y
  49. Done.
  50. Note that `MyDevice` can be any arbitrary name you'd like. Also, you can add as many devices as you want.
  51. Next, configure users you want to be able to authenticate with pam_usb:
  52. # pamusb-conf --add-user root
  53. Which device would you like to use for authentication ?
  54. * Using "MyDevice" (only option)
  55. User : root
  56. Device : MyDevice
  57. Save to /etc/pamusb.conf ?
  58. [Y/n] y
  59. Done.
  60. Check the configuration
  61. -----------------------
  62. You can run `pamusb-check` anytime to check if everything is correctly worked.
  63. This tool will simulate an authentication request (requires your device to be connected, otherwise it will fail).
  64. # pamusb-check root
  65. * Authentication request for user "root" (pamusb-check)
  66. * Device "MyDevice" is connected (good).
  67. * Performing one time pad verification...
  68. * Verification match, updating one time pads...
  69. * Access granted.
  70. Setting up the PAM module
  71. -------------------------
  72. To add pam_usb into the system authentication process, we need to edit `/etc/pam.d/common-auth`
  73. NOTE: If you are using RedHat or Fedora this file can be known as /etc/pam/system-auth.
  74. Your default PAM common-auth configuration should include the following line:
  75. auth required pam_unix.so nullok_secure
  76. This is a current standard which uses passwords to authenticate a user.
  77. Alter your /etc/pam.d/common-auth configuration to:
  78. auth sufficient pam_usb.so
  79. auth required pam_unix.so nullok_secure
  80. The `suffient` keyword means that if pam_usb allows the authentication, then no password will be asked.
  81. If the authentication fails, then the default password-based authentication will be used as fallback.
  82. If you change it to `required`, it means that *both* the USB flash drive and the password will be required to grant
  83. access to the system.
  84. At this point, you should be able to authenticate with the relevant USB device plugged-in.
  85. scox $ su
  86. * pam_usb v.SVN
  87. * Authentication request for user "root" (su)
  88. * Device "MyDevice" is connected (good).
  89. * Performing one time pad verification...
  90. * Verification match, updating one time pads...
  91. * Access granted.
  92. Agent
  93. -----
  94. The pam_usb agent (pamusb-agent) allows you to automatically execute commands
  95. upon locking and unlocking events. Those events are generated when you insert or
  96. remove your authentication device.
  97. To configure the commands, you have to edit pam_usb's configuration file
  98. (/etc/pamusb.conf) and add agent entries into your user section.
  99. For instance, you could automatically start your screensaver as soon as you
  100. remove the device, and deactivate it when you plug the device back.
  101. GNOME (gnome-screensaver):
  102. ```xml
  103. <user id="scox">
  104. <device>MyDevice</device>
  105. <agent event="lock">gnome-screensaver-command --lock</agent>
  106. <agent event="unlock">gnome-screensaver-command --deactivate</agent>
  107. </user>
  108. ```
  109. KDE (kscreensaver):
  110. ```xml
  111. <user id="scox">
  112. <device>MyDevice</device>
  113. <agent event="lock">dcop kdesktop KScreensaverIface lock</agent>
  114. <agent event="unlock">dcop kdesktop KScreensaverIface quit</agent>
  115. </user>
  116. ```
  117. You can execute more commands by adding extra `<agent>` entries.
  118. $ pamusb-agent
  119. pamusb-agent[18329]: pamusb-agent up and running.
  120. pamusb-agent[18329]: Watching device "MyDevice" for user "scox"
  121. pamusb-agent[18329]: Device "MyDevice" has been removed, locking down user
  122. "scox"...
  123. pamusb-agent[18329]: Running "gnome-screensaver-command --lock"
  124. pamusb-agent[18329]: Locked.
  125. pamusb-agent[18329]: Device "MyDevice" has been inserted. Performing
  126. verification...
  127. pamusb-agent[18329]: Executing "/usr/bin/pamusb-check --quiet
  128. --config=/etc/pamusb.conf --service=pamusb-agent scox"
  129. pamusb-agent[18329]: Authentication succeeded. Unlocking user "scox"...
  130. pamusb-agent[18329]: Running "gnome-screensaver-command --deactivate"
  131. pamusb-agent[18329]: Unlocked.
  132. Depending on your desktop environment, you have to add pamusb-agent to the list
  133. of autostarted applications so it will be started automatically.
  134. GNOME:
  135. - Open System -> Preferences -> Sessions
  136. - Select Startup Programs and press Add
  137. - Enter pamusb-agent and press OK
  138. - Press Close
  139. KDE:
  140. cd ~/.kde/Autostart
  141. ln -s /usr/bin/pamusb-agent pamusb-agent
  142. Configuration Reference
  143. -----------------------
  144. There are many more options available to fine tune pam_usb.
  145. Check out the [configuration reference](doc/CONFIGURATION.md).
  146. Troubleshooting
  147. ===============
  148. Log Analysis
  149. ------------
  150. Both pam_usb.so and pamusb-agent use the syslog facility to log authentication
  151. attempts.
  152. This can be useful for GUI-driven applications (for instance GDM) where you
  153. don't get to see console output.
  154. Messages are logged with the AUTH facility, they are usually written to
  155. `/var/log/auth.log` but may vary
  156. depending on the operating system you're using.
  157. # tail -f /var/log/auth.log
  158. pamusb-agent[25429]: Device "sandisk" has been inserted. Performing
  159. verification...
  160. pamusb-agent[25429]: Executing "/usr/bin/pamusb-check --quiet
  161. --config=/etc/pamusb.conf --service=pamusb-agent scox"
  162. pam_usb[25485]: Authentication request for user "scox" (pamusb-agent)
  163. pam_usb[25485]: Device "sandisk" is connected (good).
  164. pam_usb[25485]: Access granted.
  165. pamusb-agent[25429]: Authentication succeeded. Unlocking user "scox"...
  166. pamusb-agent[25429]: Unlocked.
  167. Enabling debug
  168. --------------
  169. Enabling debug messages may help you find out what's wrong.
  170. To enable them, edit `/etc/pamusb.conf` and set the following option:
  171. ```xml
  172. <defaults>
  173. <option name="debug">true</option>
  174. </defaults>
  175. ```
  176. You can enable debug messages only for a specific user, device or service.
  177. ```xml
  178. <services>
  179. <service id="sudo">
  180. <option name="debug">true</option>
  181. </service>
  182. </services>
  183. ```