Menu
Anti-random
  • Contact Us
Anti-random
Yubikey 5 NFC

Importing GPG Key pairs with OpenPGP Cards

Posted on March 12, 2020March 24, 2020 by Sid

This allows you to use the GPG private key on your yubikey (or any OpenPGP security card) on a new workstation. Note that the secret key will continue to live on the card – just as we typically desire.

Since we’re using the gpg tool directly, this should work on Windows, macOS and linux.

1. Plug in your YubiKey

Plug in the YubiKey or OpenPGP card and then run

gpg --card-status

You should see the card recognized and you should see information about your card-stored keys. This is needed for gpg to ‘see’ your card-keys.

2. Import your public key

Have your public key in a file and import it. For example:

gpg --armor --import /path/to/yourpublickey

That’s it! During import, gpg automatically sees that the imported public key is for the private key on the card and you’re all set. You can verify this as follow:

$ gpg --list-secret-keys

----------------------------------------------
sec>  rsa4096 2016-03-18 [SC]
      1111111111111111111111111111111111111111
      Card serial no. = 1111 11111111  <== SECRET KEY ON CARD !
uid           [ultimate] Sid Shetye <[email protected]>
uid           [ultimate] Sid Shetye <[email protected]>
ssb>  rsa4096 2016-03-18 [E]

3. Trust your own key

gpg --edit-key "Sid Shetye"

then

trust

then

Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)

  1 = I don't know or won't say
  2 = I do NOT trust
  3 = I trust marginally
  4 = I trust fully
  5 = I trust ultimately
  m = back to the main menu

Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y

then

quit

Finally, to verify that it’s trusted as follows

PS C:\Users\sid> gpg -K
C:/Users/sid/AppData/Roaming/gnupg/pubring.kbx
----------------------------------------------
sec>  rsa4096 2016-03-18 [SCA]
      B93C88D65A5F53F7C64FD0ACE40417A78068C109
      Card serial no. = 0006 11467785
uid           [ultimate] Sid Shetye <[email protected]>
uid           [ultimate] Sid Shetye <[email protected]>
ssb>  rsa4096 2016-03-18 [E]

The [ultimate] seen in the output confirms this.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Returning to social media, curated version!
  • How I got COVID-19 and beat it!
  • File based SSH keys and agent forwarding in Windows and WSL
  • Modern online safety for parents of young kids
  • SSH on Windows with private key on Yubikey

Recent Comments

  • Dirk Gently on Running Windows 10 on an older Macbook Pro
  • Hegi on SSH on Windows with private key on Yubikey
  • Robert on Running Windows 10 on an older Macbook Pro
  • Sid on Fix your CalSpa hot tub (error code SF)
  • Birat on Running Windows 10 on an older Macbook Pro

Archives

  • August 2021
  • June 2020
  • April 2020
  • March 2020
  • October 2019
  • March 2019
  • October 2018
  • November 2017
  • April 2017
  • January 2017
  • July 2016
  • January 2016
  • March 2015
  • January 2015
  • October 2014
  • February 2014
  • November 2013
  • September 2013
  • June 2013
  • May 2013
  • January 2013
  • December 2012
  • November 2012
  • September 2012
  • December 2011
  • November 2011

Categories

  • Business
  • Fitness
  • Fix it
  • Fun
  • Governance
  • IT
  • Living
  • Miscellaneous
  • Mobile
  • Parenting
  • Startups
  • Technology
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 Anti-random | Powered by Superb Themes