allan

SmartCards - OpenSSH

Jul 18th, 2017
526
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.39 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-openssh/
  5. #
  6. # =====================================================================
  7. # Option #1: Use public/private keys on card
  8. #
  9. # Note: A Public/Private Key on the card is required. See:
  10. #    https://pastebin.com/D0geT5Ne
  11. # =====================================================================
  12. #
  13. # Output public key as SSH key
  14. $ pkcs15-tool --read-ssh-key 707db33cfbd0712e0d5cfc4238fa85be44da990d
  15. Using reader with a card: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  16. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCju5VBvBBjqR/v580MztBh5paDcaEIyd7GnAUnvKQ7N95VNs2JqyQIseubHDYipOuLSO15uOi5DEoA5gtzMym3ecjwrKNiRMwwHsdxiUhZwEVZZZd2zY5B/6oaWQ5rgiBioUbdwLEvRYS2Koe7xF7ggn+bKIyL4vUCTX681VyG7bt96f1YwNpAkH7O4pwi3AgagDHVtmVLgDCca1vQ5FV2e/Q/gRhNtqmONRX+wcdabHfdoKu+gKGBkxgR3icMlx/sF6zh+Ov//RtY0f+6R+2SUE5uIUjq/fvIfLI8l+dexB5KjEAerxvx+YH+HWKQMCDFmK7FLNOv1iA3LfDKzRJl Public Key
  17.  
  18. # ---------------------------------------------------------------------
  19. # Jump to "Login to Server" section.
  20. # ---------------------------------------------------------------------
  21.  
  22. # =====================================================================
  23. # Option #2: Import existing SSH public/private keys
  24. # =====================================================================
  25. #
  26. # Import Private SSH key
  27. # ---------------------------------------------------------------------
  28. $ pkcs15-init --store-private-key id_rsa --auth-id 01 --label 'SSH Key'
  29. Using reader with a card: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  30. Security officer PIN [Security Officer PIN] required.
  31. Please enter Security officer PIN [Security Officer PIN]:
  32. User PIN [John Doe] required.
  33. Please enter User PIN [John Doe]:
  34.  
  35. # Display all private keys
  36. # Note: SSH key has a different ID
  37. # ---------------------------------------------------------------------
  38. $ pkcs15-tool --list-keys
  39. Using reader with a card: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  40. Private RSA Key [Certificate]
  41.     Object Flags   : [0x3], private, modifiable
  42.     Usage          : [0x4], sign
  43.     Access Flags   : [0x1D], sensitive, alwaysSensitive, neverExtract, local
  44.     ModLength      : 2048
  45.     Key ref        : 0 (0x0)
  46.     Native         : yes
  47.     Path           : 3f0050150100
  48.     Auth ID        : 01
  49.     ID             : 707db33cfbd0712e0d5cfc4238fa85be44da990d
  50.     MD:guid        : 503f9232-5ab5-d056-3e60-c7e8fe7090d9
  51.  
  52. Private RSA Key [SSH Key]
  53.     Object Flags   : [0x3], private, modifiable
  54.     Usage          : [0x4], sign
  55.     Access Flags   : [0xD], sensitive, alwaysSensitive, neverExtract
  56.     ModLength      : 2048
  57.     Key ref        : 1 (0x1)
  58.     Native         : yes
  59.     Path           : 3f0050150101
  60.     Auth ID        : 01
  61.     ID             : 02a446cce890490859cb7a2b5f9d17e7f1e1b430
  62.     MD:guid        : 130f962e-81ff-6056-fc52-498b521dd064
  63.  
  64. # Output SSH Public Key
  65. # ---------------------------------------------------------------------
  66. $ pkcs15-tool --read-ssh-key 02a446cce890490859cb7a2b5f9d17e7f1e1b430
  67. Using reader with a card: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  68. ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA40TJocjroR4UAjWiMJ9GahgRlVUZYG8f9Szuok6WHZPtK4qwuou0/ofCzV5W2BPBb/syQiGOxb9oI1rMCbL78VL2O6LDvrkzoN9ulk9euaY6mPN73VUrgcNTVOrHb7UbNcVC877NO4Mr9aoPTSMHZJVDcQXPxY6+PxaMYIqw5TcN90OAFYRsM8BSuqUMWQLqECyT3E2KQRAFRvBx3lDgQ50MnI57f4k7z4agEtjSdpTqFY+0kS1McP0lWt3tiqGoflk1cAtwu1Zr+j3ydIVq1l5v/qOTwgJ62VhVXKX1RajP74QyuJEG6RT1/7l2bLMsw8d1+kRZZrGAxpvyZ2xhAw== SSH Key
  69.  
  70. # =====================================================================
  71. # Login to Server
  72. # =====================================================================
  73. #
  74. # Copy key to server
  75. #
  76. # Note: SSH key is from "ssh-rsa ... Key"
  77. # ---------------------------------------------------------------------
  78. #
  79. # Store key in ~/.ssh/authorized_keys
  80.  
  81. # Login to server using PKCS11
  82. # ---------------------------------------------------------------------
  83. $ ssh -I /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so -l jdoe server.name
  84. Enter PIN for 'OpenSC Card (John Doe)':
  85. jdoe@server.name ~ $
  86.  
  87. # Create or edit ~/.ssh/config and add the following line:
  88. # ---------------------------------------------------------------------
  89. PKCS11Provider /usr/lib/x86_64-linux-gnu/pkcs11/opensc-pkcs11.so
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment