basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    SSH key on a security key: ed25519-sk

    A regular SSH key sits as a file on disk: if your computer is compromised, someone can copy it. With ed25519-sk, the private key never leaves the FIDO2 hardware token, and every login requires a physical touch.

    How a hardware-backed key works

    When you generate an ed25519-sk key, the private part is created inside the FIDO2 hardware token (YubiKey or similar) and never leaves the chip. The ~/.ssh/id_ed25519_sk file on your computer holds a key handle rather than the secret itself, which tells the token which key to use. If an attacker copies that file from disk, they still can’t log in: only the token can sign the challenge after a physical touch.

    No special server setup is needed: put the normal line from id_ed25519_sk.pub (type [email protected]) into ~/.ssh/authorized_keys. The one requirement is OpenSSH 8.2 or newer on both sides. Ubuntu 24.04 ships OpenSSH 9.6; Windows’ built-in OpenSSH added FIDO2 support in 8.9.

    Create and add the key

    ssh-keygen -t ed25519-sk -O resident -O verify-required -C "yubikey-main-2026"

    Two -O options control how the key behaves:

    • -O resident stores the key handle directly in the token’s memory. On a new computer you don’t need to copy files over: plug in the token and run ssh-keygen -K inside ~/.ssh to recreate the stub files locally, or ssh-add -K to load the key into the agent for the session (ssh-agent). Requires OpenSSH 8.3+.
    • -O verify-required prompts for the FIDO2 PIN (or token biometrics) on every login in addition to touch. If the token is stolen, physical possession alone isn’t enough. Set the PIN on the token beforehand in the vendor’s utility; requires OpenSSH 8.4+.

    Add the public key ~/.ssh/id_ed25519_sk.pub to ~/.ssh/authorized_keys on the server just like a regular key (SSH keys). To make the server enforce PIN verification and reject FIDO keys without it, add this line to /etc/ssh/sshd_config.d/00-hardening.conf (sshd_config):

    PubkeyAuthOptions verify-required

    Check the config with sudo sshd -t and reload ssh while keeping your current session open (Keep the old session open).

    Backup access

    A hardware token can be lost, left at home, or broken. Having a single key in authorized_keys turns a lost token into a lockout. Keep at least two keys in authorized_keys:

    • your primary token for daily logins;
    • a backup key — a second token stored separately, or a regular ed25519 key with a long passphrase on encrypted storage.

    If the primary token goes missing, log in with the backup key and remove the old line from authorized_keys. The provider console remains the last fallback (Provider console).

    If it doesn’t work

    Key enrollment failed: invalid format when creating the key

    Cause
    The token doesn’t support ed25519-sk (older YubiKeys with firmware before 5.2.3 only support ecdsa-sk), no FIDO2 PIN is set on the token for -O verify-required, or the Windows terminal lacks permissions to access the token.
    Fix
    Set a FIDO2 PIN in the token vendor’s utility; on an older token try ssh-keygen -t ecdsa-sk; on Windows run PowerShell as Administrator.

    Permission denied (publickey) on the server even though the line is in authorized_keys

    Cause
    The server runs OpenSSH older than 8.2 and doesn’t recognize the [email protected] key type.
    Fix
    Check the server version with ssh -V. If it’s below 8.2, keep a regular ed25519 key for that server (SSH keys).

    ssh-keygen -K finds no key on the token on a new computer

    Cause
    The key was generated without -O resident, so its key handle stayed as a file on the old computer.
    Fix
    Copy the stub file id_ed25519_sk from the old computer (it’s useless without the token) or generate a new key with -O resident.

    The token is lost and no other keys are on the server

    Cause
    authorized_keys only held the key from the lost token.
    Fix
    Log in through the provider console (Provider console) and add a new key. To avoid that, keep a second backup key in authorized_keys from the start.

    How to check

    Connect by pointing explicitly to the new key:

    ssh -i ~/.ssh/id_ed25519_sk [email protected]

    The client asks for your PIN (if verify-required is set) and prompts you to touch the token, then opens the session. Unplug the token from USB and run the same command again: without the token connected, login must fail even though ~/.ssh/id_ed25519_sk is still on disk.