Yubikey with GPG
Overview
Yubikey is a hardware component that enhances security through cryptographic functions like key storage and digital signatures. Using OpenPGP/GPG on a Yubikey to digitally sign code commits and emails, or encrypt messages.
Obtain Public Key from Yubikey
Info
This section is after you've already generated keys, put them on your Yubikey, uploaded your public key to a key server, and placed the URL to that public key on your Yubikey.
- Plug Yubikey into computer
- Run
gpg --card-status
to ensure your computer sees the Yubikey - Run
gpg --card-edit
- Run
fetch
- Type
quite
- Run
gpg --edit-key $MASTERKEYID
- Type
trust
- Follow prompts
- Type
quit
Now confirm the keys are there by using:
To view the public key: gpg -k
To view the secret key: gpg -K
Generate Keys
- Run
gpg --full-generate-key
- At the prompt, specify the kind of key you want, or press
enter
to accept the default - At the prompt, specify the key size you want, or press
enter
to accept the default - Enter the length of time the key should be vaild. Press
enter
to specify the default selection, indicating that the key doesn't expire. Unless you require an expiration date, we recommend accepting this default - Verify that your selections are correct
- Enter your user ID information
- Type a secure passphrase you'll remember
- Run
gpg --list-secret-keys --keyid-format=long
command to list the long form of the GPG kys for which you have both a public and private key.
Edit the Keys
Add a photo
- Run
gpg --list-secret-keys --keyid-format=long
command to list the long form of the GPG kys for which you have both a public and private key. - From the list of GPG keys, copy the long form of the GPG key ID you'd like to add a photo to. For the rest of this procedure, the GPG key ID will be refereced with
$MASTERKEYID
. - Run
gpg --expert --edit-key $MASTERKEYID
- Type
addphoto
- Follow prompts
Send Public Key to Ubuntu Keyserver
- Run
gpg --keyserver keyserver.ubuntu.com --send-keys $MASTERKEYID
- Confirm you get the following feedback:
gpg: sending key $MASTERKEYID to hkp server keyserver.ubuntu.com
Add Public Key URL to Yubikey
- Go to keyserver.ubuntu.com and type your
$MASTERKEYID
into the search box - You should see
pub
followed by a hyperlink with your$MASTERKEYID
, right-click that link and copy the URL - Run
gpg --edit-card
- Type
admin
- Type
URL
- Paste the url you copied from step 1
- Enter your Admin PIN
Move Keys to Yubikey
- Run
gpg --edit-key $MASTERKEYID
- Select the key you want to move by using
key
followed by a number of the key
key 2
(It'll put a*
next to your selected key) - Type
keytocard
to move the selected key to your Yubikey - Make the selection based on the key your moving. [E = Encryption Key, S = Signature Key, A = Authentication Key]
- Repeat steps 2 through 5 until all your keys are on the Yubikey
- Type
save
- Type
quit