// Engineering Log
Secrets and zero trust: Part 6 — SSH keys on a hardware key: ed25519-sk and storage
Published on 2026-11-27 · Author: Mikhail Gorbachev
A private SSH key without a passphrase in ~/.ssh/id_ed25519 is the most common and the weakest option. The file can be copied from a stolen laptop, from a backup, or by malware, and the copy works anywhere and indefinitely as long as the public key is in authorized_keys on servers. There are two ways to do better:
- a key that never leaves the device: an SSH key of type
ed25519-skorecdsa-skon a FIDO2 security key (for example, YubiKey). The private part is created inside the device and is not extractable; each signature requires a touch, and optionally a PIN; - a stored key in a vault: a normal SSH key stored in Bitwarden or Vaultwarden and loaded into the agent only for the session lifetime, not written to disk.
Below are both approaches, their limitations, and the procedure to migrate from file keys.
How ed25519-sk works
The types ecdsa-sk and ed25519-sk appeared in OpenSSH 8.2, the user verification requirement (verify-required) — in OpenSSH 8.4. The sk suffix means security key. OpenSSH talks to the device over USB HID; the needed device permissions are described in the article “Part 4 — FIDO2 and YubiKey: hmac-secret, libfido2 and access rights”. The client needs an OpenSSH build with FIDO (libfido2) support: if ssh-keygen -t ed25519-sk responds No FIDO SecurityKeyProvider specified, install a build with support (on macOS, for example, OpenSSH from Homebrew) or specify the library with -w.
When creating such a key, two files also appear on disk, id_ed25519_sk and id_ed25519_sk.pub, but the “private” file does not contain a secret — it contains a key handle, an identifier the device uses to find its credential. Signing is possible only when the FIDO2 key is connected. The file itself is useless to an attacker.
The device is needed only on the client. The server only needs to understand the new key types, i.e. run OpenSSH 8.2 or newer; if you use verify-required in authorized_keys or PubkeyAuthOptions, you need server 8.4 or newer. A server with older OpenSSH will not accept sk keys, and this is the first thing to check before migrating:
ssh -V # on the client and on the serverCreating the key
ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:workWhat the options mean:
-t ed25519-sk— key type. If the device doesn’t support Ed25519,ssh-keygenwill report an error; then use-t ecdsa-sk;-O resident— store the credential on the device (more below). For resident keys the device usually requires a PIN to be preset;-O verify-required— require user verification for every signature. According tossh-keygendocumentation the only supported method currently is PIN;-O application=ssh:work— the credential name on the device. It must start withssh:; different names allow multiple resident keys on one device, for example for work and personal servers.
During creation ssh-keygen will show You may need to touch your authenticator to authorize key generation, prompt for a PIN and a touch, and then ask for a passphrase for the file. The passphrase here only protects the key handle; you can leave it empty if you rely on the PIN.
By default each signature requires a touch. The -O no-touch-required option disables that, but sshd by default rejects such signatures until the no-touch-required option is set in authorized_keys for the key. Disable touch only for automation where no human is present, and in that case use a separate key for that purpose.
Resident and non-resident keys
A non-resident key (without -O resident): the device stores nothing; all information to find the credential is in the id_ed25519_sk file. To log in you need both the file and the device. The file must be copied to every machine you use.
A resident key is stored on the device. On a new machine it can be recovered without copying files:
cd ~/.ssh
ssh-keygen -K # will ask for PIN, write files into the current directoryFor each resident key there will be files like id_ed25519_sk_rk_work and id_ed25519_sk_rk_work.pub: the name is composed from the type and the application value without ssh:. If multiple devices are connected, the keys are taken from the one you touch first.
You can avoid writing files and load resident keys into the agent directly:
ssh-add -KThe risk of a resident key is that possession of a single device is enough to log in: the key handle file can be extracted from the device itself. Dumping resident keys (ssh-keygen -K) is protected only by the device PIN: knowing the PIN, an attacker can dump the key handle, and signing then requires a single touch. With verify-required PIN is required for every signature. A non-resident key is useless if one device is stolen, but requires protecting the file and copying it between machines.
Practical rule: use resident keys only together with verify-required; use non-resident keys if you work from one or two computers and don’t want to store extra credentials on the device.
Server configuration
The public key is added to ~/.ssh/authorized_keys as a normal line:
sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29t... workOptions at the beginning of the line set requirements for that specific key:
verify-required sk-ssh-ed25519@openssh.com AAAA... workverify-required means the server will accept only signatures where the device confirmed user verification (PIN). Without this option the server does not enforce the PIN. A key created with -O verify-required receives credProtect on the device: the device will require a PIN for every signature. The server option additionally rejects any signatures where user verification is not asserted, for example from keys without this flag.
To require touch and PIN for all FIDO keys on the server, use sshd_config:
PubkeyAuthOptions touch-required verify-requiredtouch-required forbids overriding touch via no-touch-required in authorized_keys. Enable verify-required globally only after all sk keys have been recreated with this option, otherwise older keys will stop working. The PubkeyAuthOptions parameter appeared in OpenSSH 8.4: on an older server sshd -t will return Bad configuration option.
If the server restricts allowable algorithms, check it:
sudo sshd -T | grep -i pubkeyacceptedBy default sk-ssh-ed25519@openssh.com and sk-ecdsa-sha2-nistp256@openssh.com are present. If the administrator set a custom list, add the needed type. Prior to OpenSSH 8.5 the parameter was named PubkeyAcceptedKeyTypes; the old name works as a synonym.
After editing — sudo sshd -t && sudo systemctl reload ssh (on some distributions the service is called sshd). Other server hardening — firewall and lockout against brute force — is described in the “Protecting a Linux server” series, for example in the article “Protecting a Linux server: Part 2 — Fail2ban against password guessing”.
Why you cannot import an existing key into FIDO2
A common question: I already have id_ed25519, can I put it on a YubiKey? In FIDO2 — no. The kernel.org documentation on FIDO2 tokens says plainly: “It is not possible to load a pre-existing ssh key onto a FIDO2 token”. OpenSSH does not provide import for sk keys: the private part is always generated inside the device.
An existing key can be imported into other YubiKey applications, with caveats:
- PIV:
ykman piv keys importwrites the key into a slot, and OpenSSH can use it via PKCS#11; - OpenPGP: requires GnuPG and
gpg-agentacting as the SSH agent. If the key was generated on the device, it cannot be restored without an external backup if the YubiKey is lost.
Usually the simpler path is: create a new sk pair, replace the public key on servers, and delete the old one.
Procedure to replace keys on servers
Create the new
skkey on your main device.Create a second independent pair on a backup device. You cannot copy an FIDO2 key, so register the backup device as a separate key:
bashssh-keygen -t ed25519-sk -O resident -O verify-required \ -O application=ssh:work-backup -f ~/.ssh/id_ed25519_sk_backupAdd both public keys to each server without removing the old one:
bashcat ~/.ssh/id_ed25519_sk.pub ~/.ssh/id_ed25519_sk_backup.pub \ | ssh admin@192.0.2.10 'cat >> ~/.ssh/authorized_keys'To make the server require a PIN, add the option before the key type:
verify-required sk-ssh-ed25519@openssh.com AAAA… work(requires server 8.4 or newer). Before appending, ensureauthorized_keysends with a newline, otherwise the first added line will be concatenated with the last existing one.Without closing your current session, in another terminal test logging in with each new key separately:
bashssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_sk admin@192.0.2.10 ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519_sk_backup admin@192.0.2.10IdentitiesOnly=yesprevents the client from silently using an old key from the agent.Only after successful verification remove the old key line from
authorized_keys, and delete the old key from all locations it was stored: from~/.ssh, backups, and vaults.
Store the backup device separately from the primary. If the primary is lost: log in with the backup, remove the lost key line from all servers, create a new pair on a new device and register it in the same order. The more servers you have, the more useful it is to keep a “key — where it’s installed” list: if a device is lost it shows where you need to remove the key line.
SSH key in Bitwarden
If you don’t have a hardware key or you need to use an existing key (for example, its public part is already registered with a client), it can be stored in Bitwarden or Vaultwarden. There is an “SSH Key” record type (in the CLI — type=5) with fields for the private and public key and the fingerprint. According to Bitwarden documentation the app generates only Ed25519 keys itself, and you can import keys in OpenSSH or PKCS#8 formats; PuTTY keys are not supported. The key material cannot be changed after creating the record.
On a graphical workstation it is convenient to use the desktop application’s SSH agent. It is enabled in settings (“Enable SSH agent”); on Linux and macOS you point SSH_AUTH_SOCK to its socket, for example ~/.bitwarden-ssh-agent.sock for a typical Linux install. A signature request when the vault is locked will open an unlock window, and with the option enabled — a confirmation as well. Requirements per documentation: OpenSSH 8.8 or newer, Git 2.34 or newer. The version the agent appeared in is not specified in the docs: if you don’t see the option in settings, update the app. Agent limitations: keys cannot be managed via ssh-add, and choosing a key for a host can be done only via IdentityFile in ~/.ssh/config, otherwise the agent offers keys in sequence and the server may refuse after several attempts. In IdentityFile specify the public key (.pub) and add IdentitiesOnly yes so the agent does not try all keys. The socket path depends on how the app was installed (Snap, Flatpak, .dmg or App Store on macOS): exact paths are in Bitwarden documentation. The key is imported in the desktop application.
On a headless server (for example a bastion) there is no desktop app, but there is the bw CLI, covered in the article “Part 3 — Bitwarden CLI on Linux: bw, session and safe operation”. You can pass the key to ssh-agent via stdin without writing it to a file:
eval "$(ssh-agent -s)" # if the agent is not running yet (when finished stop it: eval "$(ssh-agent -k)")
bw unlock # and export BW_SESSION=... from the output
bw get item <id-or-record-name> | jq -r '.sshKey.privateKey' | ssh-add -t 3600 -
bw lock
ssh-add -l # key in the agent, lifetime one hourWhat is important here:
ssh-add -reads the key from stdin; this is not documented inssh-addhelp but it works (Identity added: (stdin)). The key flows between processes and is not written to a file;-t 3600— the agent will remove the key after an hour;bw lockimmediately locks the vault after loading; the session keyBW_SESSIONthen no longer works;- the
.sshKey.privateKeyfield is tested in practice. The templatebw get template item.sshKeydoes not exist (responseUnknown template object), so the JSON for creating such a record via CLI is assembled manually based on the templateitem; bw get itemfinds a record by name; if multiple records match the command fails. It’s more reliable to specify the record ID.
The limitation of this method: while the key is in the agent, any process of the same user or root can sign via the agent on your behalf. The agent protocol does not allow exporting the key itself (root can read the agent process memory), but dumping isn’t necessary for logging into servers. Therefore keep -t short and do not forward the agent to untrusted machines (ForwardAgent no).
What an attacker gets
| Variant | Theft of a powered-off laptop | Malware running as your user |
|---|---|---|
| File without passphrase | the key immediately, if the disk is not encrypted | a copy of the key that always works |
| File with passphrase | the file, which needs brute-forcing | the passphrase via input capture and the file; key from the agent while it is loaded |
| Key in a vault | an encrypted copy of the vault: strength depends on the master password and KDF | signatures via the agent while the key is loaded; the whole key and the rest of the vault if the master password or session key are captured |
sk key | nothing without the device; with the device — a signature by touch, and with verify-required also by PIN | the key is not extractable; signing is possible only with the connected device and a touch (including via a forged request while you touch the key), and already-open SSH sessions can be used without a touch |
The sk key is the only option where compromising a computer does not give a long-term copy of the key: after cleaning the machine check server login logs for the compromise period, authorized_keys, and other places where persistence could be established (accounts, cron jobs, services). In other cases the key is considered compromised and must be rotated on all servers, like any leaked secret (“Secure Development: Part 2 — Secrets in code”).
Common errors
sign_and_send_pubkey: signing failed for ED25519-SK "/home/user/.ssh/id_ed25519_sk": device not found. The client found the key file but does not see the device. Causes:
- the FIDO2 key is not connected or a different key is connected which doesn’t have that credential;
- the user has no access to
/dev/hidraw*. Checkls -l /dev/hidraw*andid: in an SSH session theuaccessrule for the active local session does not apply, you need a group (for exampleplugdev) and a udev rule. If the device is accessible only by root, ssh behaves as if the key is not connected; - the device is held open by another program.
signing failed without device not found. ssh -vvv will show the reason. If you see invalid format, the touch was not performed in time or the key replied with another error: run the command and touch the key immediately after the prompt. For incorrect passphrase supplied to decrypt private key check the PIN and the keyboard layout you use to enter it.
Permission denied (publickey) with the device attached. The server refuses the key: OpenSSH on the server is older than 8.2 (or older than 8.4 if verify-required is in authorized_keys); the sk type is not included in PubkeyAcceptedAlgorithms; verify-required is set in authorized_keys or PubkeyAuthOptions verify-required is set on the server while the key was created without -O verify-required. Details are shown by ssh -v on the client and the sshd log on the server (journalctl -u ssh).
Key enrollment failed when creating the key. The text after the colon depends on version and device. If it says requested feature not supported, the device does not support Ed25519 or credProtect: use -t ecdsa-sk or another device. For resident keys (-O resident) the device usually requires a PIN to be set; for YubiKey set it with ykman fido access change-pin (we did not verify this command in Yubico documentation).
The agent offers the wrong key. The agent has multiple keys and the server refuses after several attempts. Specify the key explicitly in ~/.ssh/config:
Host app.example.ru
HostName 192.0.2.10
User admin
IdentityFile ~/.ssh/id_ed25519_sk
IdentitiesOnly yesRecommendation
- For personal administrative access to servers — use
ed25519-skwithverify-required, keep a second independent pair on a backup device, and addverify-requiredinauthorized_keys. - If the key cannot be replaced or you don’t have a hardware key — store the SSH key in a vault, on a workstation use the Bitwarden agent, on a headless server use
ssh-add -with a short lifetime andbw lock. - A file without a passphrase — only for automation keys with narrow privileges, with
authorized_keysrestrictions (from=,command=) and kept separate from human users’ keys.
// Contact
Need help?
Get in touch with me and I'll help solve the problem
I reply within one business day (03:00-13:00 GMT)
Or leave a request here:
// Related