⭕With Commandline
Instructions on generating GPG keys using the gpg command-line.

❊ Before You Start
We highly recommend before continuing with this guide that you view the GPG Introduction page for a brief description of what GPG keys do and the differences between Yubikey vs Software generated keys. It only takes a minute.
❊ Generating Keys
This section utilizing the gpg command-line to generate keys. Be sure to have GPG installed. If unsure, read the GPG installation guide.
MASTER KEY [C]
Launch Command Prompt, Terminal, or Powershell.
Run command:
You will see a list of options:
Select (8) RSA (set your own capabilities)
You will be asked a series of questions. Select the options below:
When asked for the desired key size, select 4096
Specify when you want the key to expire:
Enter your name, email address, and a comment for the key:
GPG will then confirm your answers:
Select O for (O)kay
You will be prompted for a password / passphrase either via a dialog box like the screenshot below, or in the console window:

Create a strong passphrase and press OK.
If you create a weak password, it will warn you to change it.
GPG will request you to move your mouse:
Simply move your mouse, open/close windows. Do as many actions on your device as you can while it generates to help with entropy.
The system will output a path to your revocation certificate. Save this file somewhere.
GPG will display your generated key:
You'll notice that this is only the [C]ertify key. We're missing [A]uthentication, [S]ignature and [E]ncryption.
SUBKEY [S]
Next, create a subkey with the [S]ignature capability.
Take note of the key id that is provided in the console. In this example we'll use 848103E9F1FFEC33DDD58C2B161C667B11784BF7
Execute command:
Console will go into gpg edit mode and show your key info:
Execute command:
You will be presented with a list of options:
Select (4) RSA (sign only)
You will then be asked for a key size. Enter 4096
Set an expiration time:
Confirm your changes.
You will be prompted to enter the passphrase you selected when you made the Masterkey in the steps above. Enter that passphrase.
Move your mouse around to generate entropy.
We now have a master key [C]ertify, and one sub key [S]ignature:
SUBKEY [E]
Create a subkey with the [E]ncryption capability.
Execute the command:
You will be presented with a list of options:
Select (6) RSA (encrypt only)
For key size, enter 4096
Select an expiration time:
Confirm your changes.
You will be prompted to enter the passphrase you selected when you made the Masterkey in the steps above. Enter that passphrase.
Move your mouse to generate entropy.
We now have a master key [C]ertify, and two sub keys [S]ignature, [E]ncryption:
SUBKEY [A]
Create a subkey with the [A]uthenticate capability.
Execute the command:
Select the options pasted below:
Select (6) RSA (encrypt only)
For key size, enter 4096
Select an expiration time:
Confirm your changes.
You will be prompted to enter the passphrase you selected when you made the Masterkey in the steps above. Enter that passphrase.
Move your mouse around to generate entropy.
Your list should look similar to the following:
Type save and the word quit
❊ Overview
You now have a GPG key pair with one master key strictly assigned to certify any new subkeys in the future, and three subkeys.
161C667B11784BF7
[sec] Secret Key
Certify
![]()
88614F297B2B2542
[ssb] Secret Sub
Sign
![]()
3272622E5D653058
[ssb] Secret Sub
Encrypt
![]()
F8BD0C1A3EB787A2
[ssb] Secret Sub
Authenticate
![]()
❊ Export
Export your keys to a location on your device with the command:
A list of your keys will appear:
Copy the key id on the top key labeled sec
PUBLIC KEY
Export your public key, enter your key id and tell the command where to export:
PRIVATE KEY
Export your private key, enter your key id and tell the command where to export:
SUBKEY
To export a subkey, use the command below and change the path / key id.
OPENSSH
Export your SSH key, copy your master key id and execute:
UPLOAD TO KEYSERVER
To upload your GPG key to an online keyserver; you can utilize one of the following commands. Be sure to replace 11784BF7 with your master key id.
If you'd like to upload your exported GPG key to a keyserver using a physical interface, check out the list of keyserver websites on the GPG Introduction page.
❊ Import to Yubikey
Unlike the PIV interface, there is no GUI (graphical user interface) that allows you to directly import your GPG keys using a program such as Yubikey Manager.
Select your method of importing:
⭕With Commandline⭕With KleopatraLast updated
Was this helpful?