How to use a YubiKey or FIDO2 key with SSH (ed25519-sk)

With the hardware key plugged in, run ssh-keygen -t ed25519-sk -O verify-required and install the resulting .pub file on the server as usual. The private key stays on the device, and each login needs a touch and a PIN. Both client and server need OpenSSH 8.2 or later, or 8.4 for verify-required. Older keys without Ed25519 support need -t ecdsa-sk instead.

Updated . The macOS error comes from the ssh-keygen included in macOS 27 (OpenSSH 10.3), and device not found from OpenSSH 10.0 on Debian 13 with no key plugged in.

What you need

  • OpenSSH 8.2 or later on both sides. That release added the ed25519-sk and ecdsa-sk key types. Check the client and the server with ssh -V. verify-required needs 8.4.
  • A key that supports Ed25519. It is optional in the FIDO standard. Yubico says YubiKeys need firmware 5.2.3 or newer. On older ones, use -t ecdsa-sk.
  • An OpenSSH build with FIDO support. See the next section if you use a Mac.

To see if a server will accept these keys, run this on the server and look for sk-ssh-ed25519@openssh.com:

sudo sshd -T | grep -i pubkeyacceptedalgorithms

On macOS, the built-in ssh is not enough

The ssh-keygen that comes with macOS gave us this:

No FIDO SecurityKeyProvider specified
Key enrollment failed: invalid format

The Homebrew build of OpenSSH depends on libfido2, which provides this support. Install it and check that your shell finds that version first:

brew install openssh
which ssh-keygen

Create the key

ssh-keygen -t ed25519-sk -O verify-required -C "you@laptop"

Touch the key when it blinks, and enter its PIN if asked. You get two files:

  • ~/.ssh/id_ed25519_sk: the handle. It looks like a private key but holds only a reference. It is useless without the hardware key.
  • ~/.ssh/id_ed25519_sk.pub: the public key.

If no key is plugged in, or the system cannot see it, you get:

Key enrollment failed: device not found

Install it and log in

ssh-copy-id -i ~/.ssh/id_ed25519_sk.pub user@server
ssh -i ~/.ssh/id_ed25519_sk user@server

The line in authorized_keys works like any other, but its type is sk-ssh-ed25519@openssh.com.

The options that matter

OptionWhat it does
-O verify-requiredEvery signature needs user verification, usually the PIN, as well as a touch. A stolen token alone is then not enough.
-O residentStores the handle on the token, so you can use it from another computer without copying a file.
-O application=ssh:workSets a name for the key. It must begin with ssh:. Useful for keeping several resident keys on one token.
-O no-touch-requiredSigning without a touch. The server must also allow it, so leave it off unless you have a reason.

Resident or not

Non-resident (default)Resident
Where the handle livesIn a file on your computerOn the token
Use on a new computerCopy the handle fileDownload it from the token
A thief needsThe token and the fileThe token, and the PIN if you set one

A resident key is convenient, but anyone holding the token can retrieve the handle, so combine it with a PIN:

ssh-keygen -t ed25519-sk -O resident -O verify-required -C "you@laptop"

On another computer, get the files or load the key directly into the agent:

ssh-keygen -K
ssh-add -K

ssh-keygen -K writes the files into the current directory.

Require a PIN from the server side

A key created without verify-required can still be held to it by the server. Add the option at the start of its line in authorized_keys:

verify-required sk-ssh-ed25519@openssh.com AAAA... you@laptop

Plan for a lost token

If the token is gone, the key is gone. Enroll two tokens, install both public keys on each server, and keep the second one somewhere safe. Keep another way in as well, such as a console from your hosting provider, before you turn off other logins.

Keep the handle files, and a note of which servers each token opens, in one place such as an SSH key manager with an encrypted vault.

Questions

Can the private key be copied off the YubiKey?

No. According to the OpenSSH release notes, the private part of the key is unique to each token and cannot be exported. That is also why you should enroll a second token as a backup.

Do I still need a passphrase?

It is optional. The handle file is not enough without the token, and a PIN with verify-required covers the case of a stolen token. A passphrase on the handle file adds another step if you want one.

Can I use the same YubiKey on several computers?

Yes. With a resident key, run ssh-keygen -K on the new computer to get the files back from the token. With a non-resident key, copy the handle file id_ed25519_sk to the new computer. Either way, each login still needs the token.

Sources

More in Keys and login

All guides