A chapter-by-chapter guide to setting up and using a YubiKey from the Linux CLI (Debian/Ubuntu and Fedora)

9 notes
YubiKey 1 — Installation (Debian/Ubuntu and Fedora) Install GnuPG, pcscd and ykman, and make sure your YubiKey is detectedOct 1, 2025
YubiKey 2 — First-time setup (the bare minimum) Replace every default PIN, PUK and management key before using your YubiKeyOct 1, 2025
YubiKey 3 — TOTP codes (OATH) Store authenticator (TOTP) codes on your YubiKey and get them from the CLI or a rofi menuOct 1, 2025
YubiKey 4 — SSH with FIDO2 Create an SSH key that lives on your YubiKey using FIDO2 (ed25519-sk)Oct 1, 2025
YubiKey 5 — OpenPGP: GPG and SSH Create GPG keys, move the subkeys to your YubiKey and use them for signing, encryption and SSHOct 1, 2025
YubiKey 6 — age encryption (PIV) Encrypt files with age using keys stored in the YubiKey's PIV applicationOct 1, 2025
YubiKey 7 — Linux login with PAM (sudo, desktop, TTY) Use your YubiKey for sudo, desktop (GDM) and TTY login with pam_u2f on Ubuntu and FedoraOct 1, 2025
YubiKey 8 — Troubleshooting Fixes for common YubiKey problems on Linux: card not found, wrong SSH agent, locked PINOct 1, 2025
YubiKey 9 — Disk encryption (LUKS) and Git signing Unlock your encrypted disk with your YubiKey at boot, and sign your Git commits with an SSH key on the YubiKey.Nov 28, 2026
README.md PDF

🔐 YubiKey on Linux — Get Started the Safe Way

A practical guide to using a YubiKey from the Linux command line. Commands are given for Debian/Ubuntu (apt) and Fedora (dnf).

Hardware tokens can raise your security to a very high level — but only when they are configured and used correctly. A badly configured token gives you a false sense of security, not actual protection.


📚 Chapters

Work through chapters 1 and 2 first. After that, pick the chapters for the functions you actually use.

#ChapterWhat you getRequired?
1InstallationAll packages, pcscd, ykman (Debian/Ubuntu + Fedora)✅ Yes
2First-time setupReplace every default PIN, PUK and key✅ Yes
3TOTP codes (OATH)Authenticator codes on the YubiKey, clipboard + rofi helpersOptional
4SSH with FIDO2The simplest secure SSH key — good place to startOptional
5OpenPGP: GPG + SSHGPG subkeys on the YubiKey, used for email, Git signing and SSHOptional
6age encryption (PIV)File encryption with age and multiple YubiKeysOptional
7Linux login with PAMYubiKey for sudo, desktop and TTY loginOptional
8TroubleshootingCard not found, wrong SSH agent, PIN locked, …Reference
9Disk encryption and Git signingUnlock your LUKS disk with the YubiKey, sign Git commitsOptional

Suggested learning path: 1 → 2 → 3 → 4 → 5. SSH with FIDO2 (chapter 4) is a good warm-up; OpenPGP (chapter 5) is more complex but more powerful.


🧩 What can a YubiKey do?

CategoryFunctionDescriptionPINTouchChapter
🔑 Modern authFIDO2WebAuthn / passkeys, SSH -sk keys, PAM login✅✅4, 7
U2FOlder version of FIDO (second factor only)❌✅7
🔢 CodesOATH-TOTPAuthenticator codes (like Google Authenticator)Optional passwordOptional3
Yubico OTPYubico’s own one-time-password format❌✅—
🪪 Keys & certificatesPIVSmartcard: certificates, VPN, age✅Optional2, 6
OpenPGPGPG keys for email, signing and SSH✅Optional2, 5
⚙️ Advanced / legacyChallenge-responseLUKS, custom scripts❌Optional—
Static passwordTypes a fixed password (not recommended)❌✅—

🚨 Golden rules

  1. Change every default (chapter 2) before you trust the key with anything.
  2. Buy two YubiKeys. Register both everywhere. One is a backup that stays in a safe place.
  3. Store your PUK, management key and GPG backups offline (paper, QR code, encrypted USB in a safe).
  4. Never use SSH agent forwarding (ssh -A / ForwardAgent yes). Use ProxyJump instead (see chapter 5).
  5. Test in a second terminal before you log out when changing login/PAM settings.

📖 Source

Partly based on and modified from Yubico’s guide 👉 Securing SSH with FIDO2