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.

251 lines
8.3 KiB

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