yubikey

YubiKey can work very effectively on a NixOS installation in the cloud (e.g., a VPS on Hetzner, AWS EC2, DigitalOcean, Linode, GCP, Azure, or any provider running NixOS), but the way it works depends on what you’re trying to achieve and the physical reality of the cloud environment.

Since cloud instances are remote headless servers with no physical USB access from your local machine, you cannot plug the YubiKey directly into the cloud VM. Instead, YubiKey enhances security through these main patterns on NixOS cloud setups (all well-supported and commonly used in 2026):

Modern OpenSSH (≥ 8.2, which NixOS has had for years) supports FIDO2 resident/discoverable keys stored directly on the YubiKey hardware. This is phishing-resistant, hardware-bound, and perfect for cloud servers.

This is the cleanest, most secure way for cloud NixOS in 2026 — no software keys exposed, hardware protection against extraction.

2. Challenge-Response / U2F as Second Factor (via pam_u2f)

Use YubiKey as a second factor for SSH login (after password or pubkey).

3. GnuPG / OpenPGP Smartcard Mode (YubiKey as PIV/OpenPGP card)

Store GPG keys on YubiKey, use for SSH via gpg-agent.

4. Edge Cases & Advanced Tricks for Cloud

Summary: Best Practices for NixOS Cloud + YubiKey (2026)

GoalBest MethodRequires Local YubiKey Plug-in?Cloud-Side Config Needed?
Secure SSH loginFIDO2 resident keysYes (during key gen & use)Just authorizedKeys
2FA on top of pubkey/passwordpam_u2f challenge-responseYes (enrollment)Yes (PAM module)
Git commit signing from cloudGPG on YubiKey + agent forwardYesgpg-agent + SSH_AUTH_SOCK
Passwordless sudo (console)pam_u2fYesYes

Bottom line: Yes — YubiKey works excellently on cloud NixOS, mostly from your local machine protecting the authentication to the remote server. The cloud instance itself stays minimal and never sees the private key material. Use FIDO2 resident keys for the simplest, strongest setup — it’s declarative in NixOS, phishing-resistant, and widely used by NixOS users securing remote infra.