December 1, 2026

It’s a little shocking that it’s been almost a decade since I first started using Yubikeys. Some may have read the writeup I did then: Figuring out GPG, SSH and U2F with YubiKey 4. How the times have changed since then! Particularly recently with all the rumours and innuendo surrounding AI being able to crack RSA – which turned out to be the biggest nothingburger (honestly, wtf are these people thinking spreading rumour like that? 🤬). Before the news of the “holy crap there’s actually nothing here!” I had decided to take some time and evaluate the crypto usage I have here, particularly related to GPG (which I use to sign every git commit) and SSH (the importance of which should be self-evident).
Unfortunately, as of this writing, PQC support for Yubikeys is in beta so there’s nothing that can be bought or used as of yet. There’s also some neat new features in more recent firmware versions (5.7 and higher) that unfortunately you can’t update older Yubikeys to take advantage of. So while I do have some Yubikey 5’s, they’re all 5.4.x and rather than buying new keys to take advantage of the new features, I’m going to hold out until the PQC-ready Yubikeys are available and upgrade them all, and the keys I use, then.
That said, I don’t want to rely on my 4096 RSA keys anymore. Despite the hype to pump Anthropic’s stock (frankly, that’s the only reason I can think of for how they marketed the cryptopocalypse!), there are better algorithms available and supported on these older Yubikeys. As a result, this post will document my switch to the Curve25519 elliptic curve cryptography (ECC) key type. Interestingly, I learned a new thing today! I had no idea that Daniel J. Bernstein created it! I remember his great work with qmail and [djbdns](https://annvix.com/using_djbdns_with_mandrakelinux/, which I used for years. Small fanboy sidetrack ;)
Anyways, as part of this effort there are a few things I need to do and I’m going to document it all from scratch as a number of things have changed since I last wrote about this almost a decade ago. For one, I have multiple Yubikeys. For each, I’m content with a unique SSH keypair, however I want the exact same GPG key. This means that we can’t create the GPG key directly on the Yubikey, we need to create it as one would normally create it on their system and then move it to each Yubikey. This is a destructive move, so we need to keep the original secret key and secure it. That means we have to create it carefully.
In my case, that meant a laptop without an internet connection that was going to be reinstalled anyways. I did this on a mac laptop, with FileVault enabled. With no internet access and the drive content being fully wiped and reinstalled, the secret key wouldn’t be in a cache, in memory, or hiding somewhere on disk for a potential attacker (or AI agent) to find. Unlikely, true, but if we’re not going to take ecurity seriously why bother having a Yubikey in the first place? 🤔
If you’re not going to nuke a laptop, you can do this with a live-boot USB as well, although that’s likely going to require Linux. Most of these commands should be the same, however I did not try it on Linux.
When I initially did this nearly a decade ago, it wasn’t possible to use macOS fully so I did the heavy lifting on Fedora. That is no longer necessary (although you obviously still could). And in my case, there was existing key material (GPG and SSH keys) on the cards so these will be destructive changes. In other words, for your SSH logins, you definitely want an alternate (either a temporary keypair that you can use to login to add your new key). I leave that prep-work as an exercise to the reader.
Additionally, my setup uses GPG to handle the SSH keys rather than anything native to the Yubikey or OpenSSH itself. In the process of figuring some of this out, I found that macOS’ build of ssh is a little different than upstream so some of the capabilities you’d likely get on Linux you won’t get on macOS. Thankfully using the gpg-agent works around many of these limitations (other than you can’t store multiple keys on a single Yubikey with the newer FIDO2 standards, which is unfortunate but doesn’t much matter to me since none of my Yubikeys have firmware 5.7+). Notably, not everyone will use the gpg-agent to handle SSH connections, but this is how I’ve been doing it for the last 10 years and it has worked wonderfully – no need to reinvent what works.
That aside, let’s get on with it. The first thing we want is to install the Yubikey Manager if it’s not already installed:
brew install ykman
This will let you fine-tune some of the Yubikey settings. I won’t go into it here, but things like ykman opengpg info will give you information on the card.
This is where I disconnected from the network because I need the new GPG key generated securely.
gpg --full-generate-key
The output will look like the following. I set the key so it doesn’t expire, selected ECC (sign and encrypt) and chose Curve 25519 for the elliptic curve to use. Then you need to provide your identity for the key,
gpg (GnuPG) 2.5.24; Copyright (C) 2026 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Please select what kind of key you want:
(1) RSA and RSA
(2) DSA and Elgamal
(3) DSA (sign only)
(4) RSA (sign only)
(9) ECC (sign and encrypt) *default*
(10) ECC (sign only)
(14) Existing key from card
(16) ECC and Kyber
Your selection? 9
Please select which elliptic curve you want:
(1) Curve 25519 *default*
(4) NIST P-384
(6) Brainpool P-256
Your selection? 1
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.
Real name: Vincent Danen
Email address: [email protected]
Comment:
You selected this USER-ID:
"Vincent Danen <[email protected]>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: revocation certificate stored as '/Users/vdanen/.gnupg/openpgp-revocs.d/BUNCHOFDIGITS.rev'
public and secret key created and signed.
pub ed25519/0x688FC94DD76743AA 2026-12-01 [SC]
Key fingerprint = 346A D3DF 2A90 A521 EBD6 F5A1 688F C94D D767 43AA
uid Vincent Danen <[email protected]>
sub cv25519/0xBUNCHOFDIGITS 2026-12-01 [E]
Key fingerprint = 1472 069D FBFD EF82 53E4 6C5E 5159 AC3E 9274 51C7
Now we need to get the key id, which is the sec ed25519/ line, the hex string afterwards is the key id. I’m just keeping my actual key ID and fingerprint here because hey, it’s a great way to validate the authenticity of the new key (which you can also get here).
❯ gpg --list-secret-keys --keyid-format LONG
gpg: checking the trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 4 signed: 1 trust: 0-, 0q, 0n, 0m, 0f, 4u
gpg: depth: 1 valid: 1 signed: 0 trust: 1-, 0q, 0n, 0m, 0f, 0u
/Users/vdanen/.gnupg/pubring.kbx
--------------------------------
sec ed25519/688FC94DD76743AA 2026-12-01 [SC]
Key fingerprint = 346A D3DF 2A90 A521 EBD6 F5A1 688F C94D D767 43AA
uid [ultimate] Vincent Danen <[email protected]>
ssb cv25519/BUNCHOFDIGITS 2026-12-01 [E]
Key fingerprint = 1472 069D FBFD EF82 53E4 6C5E 5159 AC3E 9274 51C7
The next step is to export the private key to a file. This is the secret key file necessary for loading onto subsequent Yubikeys. For me, I wanted this on an encrypted USB flash drive and rather than writing it to disk, it’s written directly to the encrypted drive. Note that it is protected by the passphrase you provided initially so they are protected by the USB filesystem encryption as well as the passphrase for the secret key itself.
gpg --armor --export-secret-keys 0x688FC94DD76743AA >/Volumes/encrypted/private-backup.asc
Now, because I still had another Yubikey with my old GPG key, I could plug it in and sign the new key. If this is the only Yubikey you have, it is important that you perform this step after you create the new key and before you import it to the last Yubikey that has the old GPG key! We want to sign the new key with the old key to establish its authenticity and legitimacy.
On the system, or using the old Yubikey, import the new key (if this is a new system you’ll need to import the new key’s public key which you can export with gpg --export -a KEYID). Once you have that public key, run:
gpg --edit-key 0x688FC94DD76743AA
Then use the sign command in the gpg terminal and save.
You can verify that it is signed with:
gpg --list-signatures 0x688FC94DD76743AA
It will show that it has been signed with your old key. Now you can export the public key and upload to various key servers or wherever you share your public GPG key.
If your Yubikey (the one you want to replace the old key with the newly generated key) is not inserted already, insert it now. The following steps will be taken for every Yubikey that needs this new GPG key. If, like me, you have an existing key, you can use ykman to verify what’s there now and what’s there when we’re done. In particular, you’re looking for the fingerprints for the Signature, Decryption and Authentication keys. Keep a note of them.
ykman openpgp info
Now we need to use GPG to move the private keys to the Yubikey.
gpg --edit-key 0x688FC94DD76743AA
Select the first key with key 1 and an asterisk will show up beside it to note it is selected. Now we will move it using keytocard which will prompt for both the passphrase of the new GPG key as well as the admin PIN for the Yubikey. It will look something like this:
gpg> key 1
sec ed25519/0x688FC94DD76743AA
created: 2026-12-01 expires: never usage: SC
trust: ultimate validity: ultimate
ssb* cv25519/0xBUNCHOFDIGITS
created: 2026-12-01 expires: never usage: E
[ultimate] (1). Vincent Danen <[email protected]>
gpg> keytocard
Please select where to store the key:
(2) Encryption key
Your selection? 2
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
sec ed25519/0x688FC94DD76743AA
created: 2026-12-01 expires: never usage: SC
trust: ultimate validity: ultimate
ssb* cv25519/0xBUNCHOFDIGITS
created: 2026-12-01 expires: never usage: E
[ultimate] (1). Vincent Danen <[email protected]>
Note: the local copy of the secret key will only be deleted with "save".
This only moved the encryption key, so I had to select key 1 to deselect the first key and then select key 0 to move the authentication and signature keys.
gpg> key 0
sec ed25519/0x688FC94DD76743AA
created: 2026-12-01 expires: never usage: SC
trust: ultimate validity: ultimate
ssb cv25519/0xBUNCHOFDIGITS
created: 2026-12-01 expires: never usage: E
card-no: 0006 DIGITS
[ultimate] (1). Vincent Danen <[email protected]>
gpg> keytocard
Really move the primary key? (y/N) y
Please select where to store the key:
(1) Signature key
(3) Authentication key
Your selection? 1
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
sec ed25519/0x688FC94DD76743AA
created: 2026-12-01 expires: never usage: SC
trust: ultimate validity: ultimate
ssb cv25519/0xBUNCHOFDIGITS
created: 2026-12-01 expires: never usage: E
card-no: 0006 DIGITS
[ultimate] (1). Vincent Danen <[email protected]>
Note: the local copy of the secret key will only be deleted with "save".
gpg> keytocard
Really move the primary key? (y/N) y
Please select where to store the key:
(1) Signature key
(3) Authentication key
Your selection? 3
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
sec ed25519/0x688FC94DD76743AA
created: 2026-12-01 expires: never usage: SC
trust: ultimate validity: ultimate
ssb cv25519/0xBUNCHOFDIGITS
created: 2026-12-01 expires: never usage: E
card-no: 0006 DIGITS
[ultimate] (1). Vincent Danen <[email protected]>
Note: the local copy of the secret key will only be deleted with "save".
gpg> save
In order to program the second Yubikey, the secret key needs to be deleted from the system, although for me it was deleted as part of the move. It doesn’t hurt to issue the command again anyways just to be sure.
gpg --delete-secret-key 0x0DAA37040952A5BE
Now that we have one done, we can do the next. This will involve importing the secret key from the encrypted flash drive and performing the same steps.
gpg --import /Volumes/encrypted/private-backup.asc
Again, use ykman openpgp info and make note of the three key’s fingerprints, and then move the key over:
gpg --edit-key 0x688FC94DD76743AA
An abridged output of the commands looks like the following:
gpg> key 1
...
gpg> keytocard
Please select where to store the key:
(2) Encryption key
Your selection? 2
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
...
Note: the local copy of the secret key will only be deleted with "save".
gpg> key 0
...
gpg> keytocard
Please select where to store the key:
(1) Signature key
(3) Authentication key
Your selection? 1
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
...
gpg> keytocard
Please select where to store the key:
(1) Signature key
(3) Authentication key
Your selection? 3
gpg: WARNING: such a key has already been stored on the card!
Replace existing key? (y/N) y
...
Note: the local copy of the secret key will only be deleted with "save".
gpg> save
gpg: deleting copy of secret key failed: No secret key
gpg> quit
Save changes? (Y/n) n
Quit without saving? (y/N) y
I’m not sure why this fails, but this is why using ykman opengpg info before and after is helpful as I could clearly see the changes were made.
The SSH key is actually already there and can be easily obtained by executing:
ssh-add -L
Look for the one that looks similar to:
ssh-ed25519 ... cardno:xxx
This is the public ssh key that you want to copy to all the places: GitHub, GitLab, any other git forge, servers you log into remotely via SSH. When you try to access the private key on the Yubikey to login, you’ll be asked for your PIN. An easy way to do this is to use ssh-copy-id user@host which will copy all private keys that ssh-add has access to.
Interestingly and unexpectedly (because with my RSA keys, each card had a different SSH key) it’s the same SSH key on each Yubikey, meaning each Yubikey has the identical private GPG and SSH key. In other words, if you lose one, while you can still log into the same systems with another, it also means that if one is compromised or lost you have to treat them as though they were all compromised or lost.
This was a little maddening to fully figure out. AI helped a bit, but I ran into a few problems along the way. The biggest one perhaps is that the Yubikey 4 (of which I thankfully only had one) doesn’t support ECC so I spent a significant amount of time trying to import the new ECC keys to a Yubikey that doesn’t support it. And neither GPG nor the Yubikey itself made that obvious. Fortunately, I have another Yubikey that I’m able to use and the older key will be factory reset and destroyed.
If you’re like me and you sign your git commits, you’ll want to edit ~/.gitconfig and change the signingKey option from your old key to your new one. You can get the ID using gpg --list-secret-keys --keyid-format=long and looking for the line similar to the following:
sec ed25519/<KEYID> YYYY-MM-DD [SC]
In particular you want to ensure that [SC] is at the end of the line as that is your signing key.
The documentation here is mostly for myself as I know in a year or two I’ll be doing it all again with new PQC-capable Yubikeys, but until then, I feel just a wee bit safer knowing I’m using some stronger crypto even it isn’t entirely ready for Q-day.
Finally, it’s a good idea to upload your new public key to keys.openpgp.org and keyserver.ubuntu.com. Not sure what’s going on with pgp.mit.edu but it took too long to upload the key so… I moved on. For those who want my key, you can also obtain it from my site.
Anyways, I know this will be helpful to future-me, and hopefully it’s helpful to someone else out there as well!