Generate PGP for Yubikey
On Windows
- Open a command prompt and execute the following command:
gpg --expert --full-gen-key
- Choose the first (default) option
RSA and RSA (default)
by pressing1
. - When asked, create a key with the length of
4096 bits
for the main and subkeys. - Enter an expiration date. (for example
1y
).
I recommend to always set an expiration date for security purposes and to choose a date between 1 and 2 years. longer than or exactly 1 year to keep it usable but shorter than 2 years for security purposes. When the key almost expires (set the date in your calendar!) you can change the expiration date and (if you have published / shared your public key) publish/share your new key with the edited expiration date. This way, when you have lost your key, it won't be 'active' till the end of time, and you may use the same key indefinitely or untill you revoke your key (for whatever reason).
- Enter your real name.
- Enter your E-mail address.
- Enter a comment (if desired).
- Press
O
if you are satisfied. - Enter a strong Passphrase to secure your private key. This is not your pin/puk/admin code or your management key, but a new passphrase which you should keep safe.
- Now you can see that two keys have been added, the main key with usage
SC
and a subkey with usageE
. SC is for 'signing and certifying' while E stands for 'Encryption'. The yubikey has support for three keys named: Signing, Encryption and Authentication.C
is essentially your digital identity and is the only key capable of certifying subkeys, revoke them and alter the expiration date or certify other peoples certificates (Do you know if I can trust this other person?).E
however, will grant you the possibility to encrypt or decrypt data (pssst, f7738t@#%wyfi7awy79238eug).A
is used as authentication key (who are you?) whiles
will be used to sign data (did you send that?). - Next, you need to edit the key to create a authentication and/or a signing key:
gpg --expert --edit-key [key id]
- Run the command
addkey
to create a new key and choose option8
to create a new RSA key with your own capabilities. This way, we may choose which capabilities we want to have for this key (signing, authentication, certify, etc.). - The mainkey already has Signing and Certifying enabled (
Usage: SC
) and one subkey already exists withUsage: E
Encryption capabilities. Now we only need to create theUsage: A
Authentication key. Because the 'Current allowed actions: Sign Encrypt' are enabled, We first need to toggle those to 'off' by pressingS
andE
to make sure the actions are empty. Now we toggle Authenticate by pressingA
and finish the key creation (when verified) by pressingQ
. - Create the key with 4096 bits and again an expiration date between 1 and 2 years.
- You'll be asked to enter the passphrase you just created to be able to use the private key.
- Now you have 3 keys:
SC
,E
andA
. - To quit the current session, type
save
. - Now we need to create an export which we need to keep safe in a secure location. when using the export method, the passphrase will remain on the exported secret key, you'll still need it(!) when you want to recover the secret/private key:
gpg --export-secret-key --armor [keyid] > c:\secure\location\for\the\backup.txt
. - Open the edit-key prompt again:
gpg --expert --edit-key [keyid]
- Now we can safely move the key to the Yubikey smartcard:
keytocard
- By default the main key (SC) is selected which can be stored in the signing and (1) and authenticating slot (3). Choose
1
Signature slot for this first key. - Enter your passphrase, and then enter the Yubikey admin pin (default = 12345678).
- Select the next key by typing
key 1
and again runkeytocard
followed by the selection where you want to store the key (forE
it is slot2
) the same passphrase and admin pin. - Now you have to deselect the first key by running
key 1
again and then select the second key by runningkey 2
. You can verify which key is selected with the*
after thessb
in the list of keys which is shown on screen whenever you run thekey #
command. - Again, you have to run
keytocard
, select the correct slot (forA
authentication it is slot3
), enter your passphrase and admin pin. - If you are done, run
save
to save your changes and quit gpg.
You are now done with creating an OpenPGP key, creating a backup if your secret key and move your key to your Yubikey smartcard. If you have not done so, please remember to change the default pin, puk and admin codes! You can do this using the Yubikey Manager, by using the Kleopatra GUI or using the GPG command line tool gpg --change-pin
.
Photo from: @towfiqu999999