GPG for everything
GPG (or PGP in general) is awesome. But it can do a lot more than just encrypting messages. You can use your GPG key for encryption (confidentiality), for digital signatures (integrity: non-repudiation) and authentication (integrity). The latter means, we can also use our GPG identity to authenticate SSH connections (rather than using a completely separate SSH key).
To do this efficiently, we can generate a GPG root key and generate subkeys for each of these different tasks. The neat thing about that is, that we have a single key id (identity) and use this identity for everything. You might think that this is somewhat of a security risk because we are not keeping a clear separation of responsibilities. But that is not the case. We are using a separate subkey for each of those use-cases. Our root key, the key that ties everything together, we are not actually using for any of those. In fact, when done properly, we generate our root key pair in a way, that the only capability they can be used for, is to certify our subkeys.
We generate our root key with certify capability only and have it not expire at all or set a long expiration. Our subkeys we generate for a shorter lifetime. If we now do this on a secure airgapped system, our holy root key never leaves the secure system. We only export our subkeys. We use these for our everyday use until they expire or we revoke them. If they do, we just generate new subkeys.
The Plan
- Generate a new key pair with certify-only capabilities (in my case ECC (curve 22519) without expiration)
- Generate subkeys for Authentication (SSH), Encryption, and Signatures.
- Export the sub keys only and transfer them to our everyday system
Generating the root key
I have chosen, to use elliptic curve keys for all of my keys. They are stronger and generate smaller keys. They are not supported everywhere, so keep that in mind. But there is nothing keeping you from adding subkeys with different kinds of algorithms to the same root key.
Since they are slightly harder to manage, GPG requires expert mode to be able to generate ecc keys. To start our key generation, use the following command
|
|
Choose option ECC (set your own capabilities)
which should be number 11 to make sure to use ECC and to disable all other capabilities.
|
|
We are prompted for capabilities.
By default, Sign
and Certify
are enabled.
We want only Certify so we toggle Sign
off by entering S
.
|
|
Now we can enter Q
.
We are then prompted for our desired algorithm.
|
|
I want curve 25519 so i enter 1
.
For expiry, I choose 0
, because I never want this identity to expire.
I don’t mind rotating subkeys, but I want my identity to stay the same.
|
|
Then it is just the usual name, email, comment prompt. Make sure you choose a good passphrase to protect your key.
Perfect.
We now have our root key.
This test example shows, that the key does not have any capabilities beyond certification ([C]
)
|
|
Generating the subkeys
Now that we have our root key, we can edit it to add subkeys. If we want ECC keys, then we will again need the expert flag.
|
|
This will open a gpg prompt.
Type addkey
to exactly that.
For signing we can use 10
, or use 11
and set signing capabilities only.
|
|
Again, we are choosing curve 25519.
Since this is a subkey I want it to expire.
I find two years (2y
) a seinsible key lifespan.
Now we can do the same for our encryption key.
Use addkey
agian and choose option 12
(or 11
to set it manually).
For our SSH key, we want to set our own capabilities (11
), disable sign and enable authentication.
When all your subkeys are generated, type save
to save your edits.
And that’s basically it.
your key should look something like this:
|
|
Notice, that every subkey only has a single capability ([S]
, [A]
, [E]
).
Our root key can only certify subkeys ([C]
).
Exporting your keys to your everyday System
Assuming you generated this key on a dedicated system away from your actual user machine you will need to export your keys, transfer them to the other computer and import them into your keyring. However, since our root key is really just the certifier for our actual key, we don’t need it on our other system. We only need it when we need new subkeys. So for security purposes, we leave the root key in its secure location and only export the subkeys.
|
|
You can also use --armor
if you prefer ASCII text format.
Then transfer to your system and run
|
|
I’ll advise, that you get rid of that temprary keys file again
|
|