573 Words

9. Disk encryption (LUKS) and Git signing

Two more things your YubiKey can do with FIDO2, the same function you used for SSH in chapter 4:

  1. Unlock your encrypted disk at boot: insert the key, type the FIDO2 PIN, touch. No long passphrase any more.
  2. Sign your Git commits, so everyone (and GitHub) can see that a commit really came from you.

Before you start: you need a FIDO2 PIN (chapter 2), and ideally a second YubiKey as a backup.


9.1 Unlock your disk with the YubiKey (LUKS2 + FIDO2)

systemd-cryptenroll adds the YubiKey to your LUKS disk as an extra key slot. Your old passphrase keeps working, so you can always get in without the YubiKey.

⚠️ This changes how your computer boots. Keep your passphrase, and don’t remove it until you have tested a reboot with both YubiKeys.

Step 1 — Find the encrypted partition

lsblk -f                      # look for FSTYPE "crypto_LUKS", e.g. nvme0n1p3
sudo cryptsetup luksDump /dev/nvme0n1p3 | grep Version   # must say: Version: 2

FIDO2 only works with LUKS2. Fedora and Ubuntu have used LUKS2 for new installations for years.

Step 2 — Enroll the YubiKey

sudo systemd-cryptenroll --fido2-device=auto /dev/nvme0n1p3

It asks for your current disk passphrase, then the FIDO2 PIN, and then you touch the key. By default systemd then asks for the PIN and a touch at every boot. Do the same with your backup YubiKey.

Check the key slots:

sudo systemd-cryptenroll /dev/nvme0n1p3    # lists: password, fido2, fido2

Step 3 — Tell the boot process to use it

Add fido2-device=auto to the options of your disk in /etc/crypttab:

luks-1234abcd-...  UUID=1234abcd-...  none  discard,fido2-device=auto

Then rebuild the initramfs:

# Fedora (dracut)
echo 'add_dracutmodules+=" fido2 "' | sudo tee /etc/dracut.conf.d/fido2.conf
sudo dracut -f

On Ubuntu the default initramfs (initramfs-tools) does not support FIDO2 unlocking. You need to switch to dracut (sudo apt install dracut), which is a bigger change: try it on a test machine first.

Step 4 — Test

Reboot. You are asked to insert the YubiKey and type the PIN. Without the YubiKey, wait a moment and you get the normal passphrase prompt.

Remove the YubiKey again

sudo systemd-cryptenroll --wipe-slot=fido2 /dev/nvme0n1p3

9.2 Sign Git commits with your YubiKey

Git can sign commits with an SSH key, so you can use the FIDO2 key from chapter 4 (~/.ssh/yubikey). Every signed commit then needs a touch of the YubiKey.

Configure Git

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/yubikey.pub
git config --global commit.gpgsign true      # sign every commit
git config --global tag.gpgsign true         # and every tag

Let Git check signatures locally

Git needs a list of keys it trusts, the allowed signers file:

echo "$(git config user.email) namespaces=\"git\" $(cat ~/.ssh/yubikey.pub)" >> ~/.ssh/allowed_signers
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers

git commit -m "My first signed commit"       # touch the YubiKey when it blinks
git log --show-signature -1                  # Good "git" signature for you@example.com

Show “Verified” on GitHub

On GitHub, go to Settings → SSH and GPG keys → New SSH key, choose Key type: Signing Key and paste the contents of ~/.ssh/yubikey.pub. Your commits now get a green Verified badge.

💡 You can use the same public key twice on GitHub: once as an authentication key (for git push over SSH) and once as a signing key.

Already use GPG on your YubiKey (chapter 5)? Then you can sign with GPG instead: leave out gpg.format ssh and set user.signingkey to your GPG key ID.


← 8. Troubleshooting · Overview