Security keys (FIDO2) with SSH
How a hardware security key is used for SSH, the key types, and what touch and PIN mean.
A security key (a YubiKey or another FIDO2 key) holds the private key in hardware. The key can sign, but it can never be copied out. Each login needs a touch on the key, and sometimes a PIN.
Key types
OpenSSH 8.2 and later support two:
The host must support them and allow them. An older server that does not will say the key is not accepted.
Making and using one
ssh-keygen -t ed25519-sk -C "me-yubikey"
Touch the key when it blinks. If ssh-keygen stops with "Key enrollment failed", see ssh-keygen "Key enrollment failed" for ed25519-sk: feature not supported, device not found. This writes a small key handle file (id_ed25519_sk) plus the public key. The handle is not the secret: the secret stays inside the key. You need both the handle and the physical key to log in.
Resident keys
A resident (discoverable) key stores its handle on the security key too: ssh-keygen -t ed25519-sk -O resident. On another computer ssh-keygen -K can download the handles from the key. This needs a PIN.
Options
-O verify-requiredmakes the key ask for the PIN each time as well as the touch.-O no-touch-requiredlets a login happen without a touch. It is allowed only if the host accepts it. Avoid it.
Connections
- Over USB or NFC, depending on the key and the client. Some clients support USB only.
- A phone or tablet may need an adapter for the key's connector, and not every client supports every connector. Check what your client lists.
Related
- Key types
- Agent
- App guide: YubiKey and security keys
- SSH "agent refused operation": signing failed and could not add identity
- ssh-keygen "Key enrollment failed" for ed25519-sk: feature not supported, device not found
- Use an ed25519-sk security key with ssh-agent: ssh-add, providers and macOS
- SSH with a FIDO security key never asks me to touch the key