OGOPSEC Brand Mark
OGOPSECOBSIDIAN GOOSE

OGOPSEC // Dispatch

Set Up a FIDO2 Key for Linux Login with PAM

By Jamie Folsom ·

This is a careful FIDO2 Linux login setup using pam-u2f, the module that lets a FIDO2/U2F security key authenticate you to local services like sudo and your display manager. PAM sits at the center of Linux authentication, which makes it powerful and unforgiving in equal measure: a wrong line can lock you out of your own machine. We will go step by step, and we will build in the safeguards before we touch anything that matters.

Read this first: Keep a second terminal open with an active root shell for the entire process (run sudo -i in it and leave it alone). If a PAM edit goes wrong, that already-authenticated shell is how you undo it. Do not close it until you have confirmed everything works in a fresh session.

Step 1: Install the module

Step 2: Register your key into a mapping file

With your key plugged in, generate a mapping. The pamu2fcfg tool prints a line that ties your username to that specific key; you will be asked to touch the key.

To add a backup key (do this now, not later), append it with the -n flag so the first line is not overwritten:

For a system-wide, root-owned mapping instead of a per-user file, you can place entries in /etc/u2f_mappings and reference it with the module's authfile= option. A root-owned file is harder for a compromised user account to tamper with.

Step 3: Decide "second factor" or "passwordless"

How you add the PAM line decides the behavior:

  1. Second factor (password and key): add auth required pam_u2f.so. The password is still required; the key is an additional check.
  2. Passwordless / key-or-password: add auth sufficient pam_u2f.so above the password line. If the key verifies, authentication succeeds; if it is absent, PAM falls through to the password.

The cue option prints a "touch your key" prompt, which is worth adding: auth required pam_u2f.so cue.

Step 4: Test on sudo first — never on login directly

Always prove the configuration on a low-risk service before touching the display manager. Edit the sudo stack:

Add the module line near the top of the auth section, save, and then — in a different terminal from your safety root shell — run a harmless sudo true. You should be prompted to touch the key. If it fails, remove the line using your open root shell and investigate before going further.

Step 5: Extend to the display manager (optional)

Once sudo works reliably with your primary and backup keys, you can add the same line to the display manager's stack — for example /etc/pam.d/gdm-password for GNOME, or the appropriate file for your environment. Test by locking the screen and unlocking, and by starting a fresh login, all while your safety shell remains open.

Step 6: Confirm, then stand down the safety net

Only after a brand-new login and a fresh sudo both succeed with the key — and you have verified the backup key also works — should you close the root shell you kept open. That final check is the difference between a smooth upgrade and a reinstall.

What this setup does and doesn't give you

You now have a hardware-gated local login: without the key (and, if you enabled it, the key's PIN), those PAM-protected actions will not proceed. That is a meaningful upgrade against a stolen-password or over-the-shoulder scenario. Be clear about the edges, though:

  1. PAM gates interactive authentication. It does not encrypt your disk; data on a powered-off machine is unaffected by any of this.
  2. It does not protect an already-unlocked session from local malware.
  3. A misconfigured required line with no backup key is the classic way to lock yourself out — which is exactly why we registered two keys and kept a root shell open.

If you would rather not hand-tune PAM, mapping files, and backup-key lifecycle, that is precisely the integration our Dire Wolf credential ships pre-wired, with fail-closed behavior built in. However you get there, the safe pattern is the same: register a backup, test on sudo, and never edit login PAM without an escape hatch open.