allan

SmartCards - PAM Authentication

Jul 18th, 2017
593
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.95 KB | None | 0 0
  1. # The following was performed on Debian Stretch
  2. # Adapted from:
  3. #    https://ubuntuforums.org/showthread.php?t=1557180&p=9743605
  4. #    http://blog.fkraiem.org/2013/03/13/linux-smart-card-authentication-pam/
  5. #
  6. # Note: A X.509 certificate stored on the card is required. See:
  7. #    https://pastebin.com/dCypTy09
  8. # =====================================================================
  9. #
  10. # Install the PKCS11 module for PAM
  11. # Note: /etc/pam_pkcs11/cacerts and /etc/pam_pkcs11/crls are automatically
  12. #    created here.
  13. # ---------------------------------------------------------------------
  14. $ sudo apt-get install libpam-pkcs11
  15.  
  16. # Extract the pam_pkcs11.conf example file
  17. # ---------------------------------------------------------------------
  18. $ zcat /usr/share/doc/libpam-pkcs11/examples/pam_pkcs11.conf.example.gz | sudo tee /etc/pam_pkcs11/pam_pkcs11.conf
  19.  
  20. # Edit /etc/pam_pkcs11/pam_pkcs11.conf and change the 'module' line
  21. #    to the correct path of opensc-pkcs11.so.
  22. # ---------------------------------------------------------------------
  23. module = /usr/lib/x86_64-linux-gnu/opensc-pkcs11.so
  24.  
  25. # Extract the certificate from the card and store as the PAM PKCS11 CA
  26. #
  27. # Note: certificate is self-signed and its own CA
  28. # ---------------------------------------------------------------------
  29. $ pkcs15-tool --read-certificate 707db33cfbd0712e0d5cfc4238fa85be44da990d | sudo tee /etc/pam_pkcs11/cacerts/jdoe-smartcard.pem
  30.  
  31. # Rehash the certs stored in /etc/pam_pkcs11/cacerts
  32. # ---------------------------------------------------------------------
  33. $ sudo pkcs11_make_hash_link /etc/pam_pkcs11/cacerts
  34.  
  35. # Basic Test with sudo
  36. # ---------------------------------------------------------------------
  37. #
  38. # Modify /etc/pam.d/sudo from:
  39. # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  40. %PAM-1.0
  41.  
  42. @include common-auth
  43. @include common-account
  44. @include common-session-noninteractive
  45.  
  46. # To:
  47. # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  48. #%PAM-1.0
  49.  
  50. auth sufficient pam_pkcs11.so
  51.  
  52. @include common-auth
  53. @include common-account
  54. @include common-session-noninteractive
  55.  
  56. # Confirm that sudo works
  57. # ---------------------------------------------------------------------
  58. #
  59. # flush any cached passphrase
  60. $ sudo --reset-timestamp
  61.  
  62. # gain root using PKCS11
  63. $ sudo --login
  64. Smartcard authentication starts
  65. Smart card found.
  66. Welcome OpenSC Card (John Doe)!
  67. Smart card PIN:
  68. verifying certificate
  69. Checking signature
  70.  
  71. # Revert changes to /etc/pam.d/sudo
  72. # ---------------------------------------------------------------------
  73. # Remove the "auth sufficient pam_pkcs11.so" line
  74.  
  75. # Edit /etc/pam.d/common-auth to apply smartcard auth globally
  76. #
  77. # Note: It is important to add pam_pkcs11.so *BEFORE* the comment
  78. #    about the "Primary" block. Otherwise, it will be overwritten by
  79. #    pam-auth-update(8)
  80. # ---------------------------------------------------------------------
  81. #
  82. # Original:
  83. # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  84. # /etc/pam.d/common-auth - authentication settings common to all services
  85. #
  86. # This file is included from other service-specific PAM config files,
  87. # and should contain a list of the authentication modules that define
  88. # the central authentication scheme for use on the system
  89. # (e.g., /etc/shadow, LDAP, Kerberos, etc.).  The default is to use the
  90. # traditional Unix authentication mechanisms.
  91. #
  92. # As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
  93. # To take advantage of this, it is recommended that you configure any
  94. # local modules either before or after the default block, and use
  95. # pam-auth-update to manage selection of other modules.  See
  96. # pam-auth-update(8) for details.
  97.  
  98. # here are the per-package modules (the "Primary" block)
  99. auth    [success=1 default=ignore]  pam_unix.so nullok_secure
  100. # here's the fallback if no module succeeds
  101. auth    requisite           pam_deny.so
  102. # prime the stack with a positive return value if there isn't one already;
  103. # this avoids us returning an error just because nothing sets a success code
  104. # since the modules above will each just jump around
  105. auth    required            pam_permit.so
  106. # and here are more per-package modules (the "Additional" block)
  107. # end of pam-auth-update config
  108.  
  109. # Updated:
  110. # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
  111. # /etc/pam.d/common-auth - authentication settings common to all services
  112. #
  113. # This file is included from other service-specific PAM config files,
  114. # and should contain a list of the authentication modules that define
  115. # the central authentication scheme for use on the system
  116. # (e.g., /etc/shadow, LDAP, Kerberos, etc.).  The default is to use the
  117. # traditional Unix authentication mechanisms.
  118. #
  119. # As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
  120. # To take advantage of this, it is recommended that you configure any
  121. # local modules either before or after the default block, and use
  122. # pam-auth-update to manage selection of other modules.  See
  123. # pam-auth-update(8) for details.
  124.  
  125. auth    [success=2 default=ignore]  pam_pkcs11.so
  126.  
  127. # here are the per-package modules (the "Primary" block)
  128. auth    [success=1 default=ignore]  pam_unix.so nullok_secure
  129. # here's the fallback if no module succeeds
  130. auth    requisite           pam_deny.so
  131. # prime the stack with a positive return value if there isn't one already;
  132. # this avoids us returning an error just because nothing sets a success code
  133. # since the modules above will each just jump around
  134. auth    required            pam_permit.so
  135. # and here are more per-package modules (the "Additional" block)
  136. # end of pam-auth-update config
  137.  
  138. # Disable password authentication for the current user
  139. # Note: Verify smartcard auth works before locking account!
  140. # ---------------------------------------------------------------------
  141. $ sudo passwd --lock `whoami`
  142. Smartcard authentication starts
  143. Smart card found.
  144. Welcome OpenSC Card (John Doe)!
  145. Smart card PIN:
  146. verifying certificate
  147. Checking signature
  148. passwd: password expiry information changed.
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment