FIDO2 SSH keys for a VPS, with a backup key
Log in to your VPS with a hardware security key. Enrol a spare key first, test it in a second session, then make sshd demand a touch and a PIN on every login.
What a FIDO2 SSH key changes on your VPS
A FIDO2 SSH key keeps the secret half of your VPS login inside a hardware security key, so a copied key file cannot log in. You create it with ssh-keygen -t ed25519-sk, put its public half in authorized_keys, and touch the device each time you connect. This guide covers the server side. You enrol two keys and test the spare before sshd is told to refuse everything else.
FIDO2 is the open standard behind hardware security keys such as a YubiKey. OpenSSH calls these "security key" types and marks them with -sk. The order of the steps matters more than any single command. A server that accepts only one physical key is one lost key away from a locked door. So the spare key is enrolled and tested before the server is tightened, never after.
If you are still setting up the basics, read how SSH key pairs, agents and authorized_keys fit together first. This guide assumes you already log in with an ordinary key and that the session works.
How the key file on disk works
A FIDO key has two parts. The first is a key handle, stored in the private key file on your disk. The second is a private key that lives on the device, is unique to that device, and cannot be exported from it. When you log in, ssh passes the handle to the device, and the device signs the server's challenge with its internal key. The key works only while the device is attached.
The OpenSSH 8.2 release notes state the design goal directly: the private key file should be useless to an attacker who does not have the physical token. That is the main reason to use these keys. The private key file on your laptop looks like any other private key, but on its own it cannot sign anything.
What a security key stops, and what it does not
It stops a stolen key file. A leaked laptop backup or malware that copies ~/.ssh gets only the handle. Without the device, the handle cannot produce a signature, so the copy is worthless for logging in.
It does not protect a server that is already compromised. An attacker with root on the VPS does not need your key to stay there. Your sessions to that server can be watched, whatever key opened them.
It also does not protect you from touching the key at the wrong moment. Malware on your laptop can start its own ssh connection and wait. The device signs whatever request is waiting when you touch it, because the touch proves that a person is present, not which request the person meant to approve. If the key blinks when you did not just run ssh, do not touch it.
A stolen device is the remaining case. With a non-resident key, the thief needs the device and the handle file. With a resident key, the handle is on the device too. The ssh-keygen manual says plainly that storing both parts on the authenticator makes a stolen device easier to use. That is why this guide pairs resident keys with a PIN (personal identification number) on every use.
Which OpenSSH version supports FIDO2 keys
Two versions matter. OpenSSH 8.2 (February 2020) added the ecdsa-sk and ed25519-sk key types, so 8.2 is the minimum on the client, and 8.2 is the first sshd that knows these types. OpenSSH 8.4 (September 2020) added keys that need a PIN for each use, the verify-required option in authorized_keys, and verify-required for the server-wide PubkeyAuthOptions setting. A key made without that option does not have to be replaced: since OpenSSH 10.5, ssh-keygen -p -O verify-required can add the flag to an existing FIDO private key. Either way, a PIN on every login needs 8.4 on both ends.
Current distribution packages are all past 8.4. On 21 November 2026 the openssh-server packages were at least these versions:
- Debian 11: 8.4p1
- Debian 12: 9.2p1
- Debian 13: 10.0p1
- Ubuntu 22.04: 8.9p1
- Ubuntu 24.04: 9.6p1
- Ubuntu 26.04: 10.2p1
For any other server, run ssh -V on it and read the version. The newest upstream release on that date was OpenSSH 10.6p2, from 5 November 2026.
The version number is not the whole answer. OpenSSH must also be built with FIDO support. Since 9.1, portable OpenSSH turns on its built-in security key support when the libfido2 library is found at build time, unless the packager disables it. A build without libfido2 can report a recent version and still fail to make an -sk key. The real test is to generate one, which the next sections do.
Client support on Linux, macOS and Windows
On a Linux laptop, use the distribution's openssh-client and run the generation command below. If it asks you to touch the device, the build supports security keys.
On macOS, the ssh that Apple ships may not support security keys. Plug in the device and run ssh-keygen -t ed25519-sk. If it fails with an error instead of asking for a touch, install OpenSSH from Homebrew. Homebrew's openssh formula depends on libfido2 and is built with the built-in security key support. Its stable version on 21 November 2026 was 10.6p2.
brew install openssh
which ssh ssh-keygen
ssh -Vwhich should print Homebrew's paths, not /usr/bin. If it prints /usr/bin/ssh, your shell still finds Apple's copy first, so fix your PATH before you continue.
On Windows, Microsoft's Win32-OpenSSH project wiki gives the 8.9 release as the first version with FIDO support. Its examples use ecdsa-sk. The same page says that downloading resident keys with ssh-keygen -K needs an elevated administrator terminal. Run ssh -V in the terminal you actually use, because some tools bring their own copy of ssh, such as the one in Git for Windows. The project's issue tracker also has an open report that ssh-keygen -K returns an invalid format when restoring FIDO2 keys on a new machine, so test the recovery step on Windows before you depend on it.
Prepare both security keys
You need two devices: a primary that stays with you and a spare that lives somewhere else. Set a FIDO2 PIN on each one with the vendor's tool before you start. The ssh-keygen manual says resident keys typically require a PIN to be set before generation, and verify-required asks for that PIN on every login.
For a YubiKey, Yubico's documentation adds some device limits. ed25519-sk needs firmware 5.2.3 or newer. Older firmware should use ecdsa-sk. Resident keys also need firmware 5.2.3 or newer and a FIDO2 PIN. A forgotten PIN can only be cleared by resetting the FIDO2 application in YubiKey Manager, and that reset deletes every FIDO2 credential on the device. A forgotten PIN therefore means a lost key, which is one more reason for the spare. The number of resident keys a device can hold varies by model, so check your own device's documentation if you plan to store many.
Choose the ssh-keygen options
Each option below changes how the key behaves. Pick them once, because apart from the touch and PIN flags, changing them later means a new key.
-t ed25519-skmakes an Ed25519 key on the device. Every FIDO token must implement ECDSA P-256, but hardware support for Ed25519 is less common. If your device refuses Ed25519, use-t ecdsa-sk.-O residentstores the key handle on the device itself. On a new computer,ssh-keygen -Kdownloads it again, so you do not need to copy the handle file around.-O verify-requiredmakes the device ask for its PIN on every use, in addition to the touch.-O application=ssh:vpsreplaces the default application string, which isssh:. The new string must begin withssh:. A separate string lets one device hold separate resident keys, for example one for your VPS and one for work, and keeps them easy to tell apart.
Touch is on by default. The server refuses signatures made without a touch unless an authorized_keys option allows them, so leave -O no-touch-required out of this setup.
Enrol the primary key and the spare
Plug in the primary device only. Then generate the primary key:
ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:vps -C "vps primary" -f ~/.ssh/id_vps_primary_skssh-keygen asks for the device PIN and a touch, then for a passphrase for the handle file. You may leave the passphrase empty, since the file cannot sign without the device. A passphrase adds one more thing an attacker needs.
Now unplug the primary, plug in the spare, and repeat with a different file name and comment:
ssh-keygen -t ed25519-sk -O resident -O verify-required -O application=ssh:vps -C "vps spare" -f ~/.ssh/id_vps_spare_skThe two keys use the same application string, which is fine because they live on different devices. Check the result:
ls -l ~/.ssh/id_vps_*
cat ~/.ssh/id_vps_primary_sk.pub ~/.ssh/id_vps_spare_sk.pubYou should see four files. Each .pub line starts with sk-ssh-ed25519@openssh.com, or with sk-ecdsa-sha2-nistp256@openssh.com if you used ecdsa-sk.
Add both public keys to authorized_keys
Use your current, working login to append both public keys in one step. Public keys are not secret, as the guide on sharing an SSH public key explains, so sending them over this session is safe.
cat ~/.ssh/id_vps_primary_sk.pub ~/.ssh/id_vps_spare_sk.pub | ssh alice@203.0.113.10 'cat >> ~/.ssh/authorized_keys'Next, log in to the server and put verify-required in front of both new lines. This option makes sshd reject any signature from that key unless the device says it verified the user, for example with the PIN. The flag in the key file is the client's side. The authorized_keys option is the server's check.
sed -i 's/^sk-/verify-required sk-/' ~/.ssh/authorized_keys
grep -c '^verify-required sk-' ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keysgrep -c should print 2. The two lines now look like this:
verify-required sk-ssh-ed25519@openssh.com AAAA... vps primary
verify-required sk-ssh-ed25519@openssh.com AAAA... vps spareWrong permissions on this file, or on ~/.ssh, make sshd refuse it, and the client only sees a generic refusal. If a key is refused later for no clear reason, work through the causes of Permission denied (publickey).
Test the spare key in a second session
Keep your current session open. Do not close it until every test in this section passes. It is your way back if something is wrong.
Unplug the primary and plug in the spare. In a new terminal, log in with the spare's file only:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_vps_spare_sk alice@203.0.113.10IdentitiesOnly=yes stops ssh from also offering your old key or keys from the agent. Without it, the old key can log you in and the test proves nothing. It also avoids the Too many authentication failures error when the agent holds several keys. You should be asked for the PIN, then the device should ask for a touch, and then you get a shell.
Prove which key opened the session. In the old session, read sshd's log:
sudo journalctl -u ssh -n 20 --no-pagerLook for an Accepted publickey line that names ED25519-SK and a SHA256: fingerprint. On your laptop, ssh-keygen -lf ~/.ssh/id_vps_spare_sk.pub prints the spare's fingerprint. The two must match. Then swap the devices and run the same test with the primary.
Finally, test recovery the way you would use it after losing your laptop. On another computer, or in an empty directory, plug in the spare and download its resident key:
mkdir -p ~/sk-restore && cd ~/sk-restore
ssh-keygen -K
ls -lssh-keygen may ask for the PIN. It writes a public and a private key file into the current directory for each resident key it finds. Use the private file it wrote with ssh -o IdentitiesOnly=yes -i <that file>, and confirm the login works. When several devices are attached, ssh-keygen -K takes keys from the first one you touch, so attach one at a time. After the test, store the spare away from the laptop.
Keep the provider console as the way back in
Before you tighten sshd, make sure you have a way in that does not use SSH. If your provider offers a web or VNC console in its control panel, open it and log in once now. A console login uses the account password, not your keys, so a broken sshd_config cannot lock you out of it.
If your user was created with an SSH key and no password, the console shows a login prompt you cannot pass. Set a password for your sudo user first, as changing a VPS password on Ubuntu shows:
sudo passwd aliceThen log in through the console with that password and log out again. Now you know the console works.
Tighten sshd to accept only security keys
Only now, with both keys tested and the console checked, change the server. First read the values sshd uses today:
sudo sshd -T | grep -E '^pubkey(authoptions|acceptedalgorithms)'On a server with default settings, pubkeyauthoptions shows none. The algorithm list is long and differs between OpenSSH versions. Create /etc/ssh/sshd_config.d/10-fido2.conf with two lines:
PubkeyAuthOptions verify-required
PubkeyAcceptedAlgorithms sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.comThe file name starts with 10- for a reason. On Debian and Ubuntu, sshd_config includes the sshd_config.d files at its top, and for most keywords sshd uses the first value it reads. A low number makes your file win over later drop-ins.
The two lines do different jobs. PubkeyAuthOptions verify-required requires a PIN-verified signature from every FIDO key, server-wide, so a key added later without the per-line option is still held to it. It has no effect on ordinary key types. An old ssh-ed25519 key still logs in with this line alone. PubkeyAcceptedAlgorithms is the line that refuses ordinary keys: sshd now accepts only the two security key signature types.
On Debian 11, which ships OpenSSH 8.4, the keyword is PubkeyAcceptedKeyTypes. OpenSSH 8.5 renamed it to PubkeyAcceptedAlgorithms and kept the old name as an alias. If you log in with SSH certificates, add sk-ssh-ed25519-cert-v01@openssh.com and sk-ecdsa-sha2-nistp256-cert-v01@openssh.com to the list too.
Check the syntax, then reload:
sudo sshd -t && sudo systemctl reload ssh
sudo sshd -T | grep -E '^pubkey(authoptions|acceptedalgorithms)'sshd -t prints nothing when the file is valid. The second command should now show verify-required and your two algorithms.
Keep the old session open and test from a new terminal. The security key login must still work. The old key must now fail:
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 alice@203.0.113.10On a server with password logins turned off, this ends with Permission denied (publickey). If you have not turned them off yet, the SSH hardening guide covers that step.
Test any old ECDSA key as well, if one is in authorized_keys. OpenSSH 10.3 fixed an incomplete application of PubkeyAcceptedAlgorithms to ECDSA keys, and every distribution release listed above ships an older version. The safest step is to delete old keys from authorized_keys once the security keys work. The algorithm list is then a second lock, not the only one.
One more consequence: anything that logs in unattended with an ordinary key stops working. Backup jobs and deploy scripts cannot touch a security key. Move them to a separate user or server before you reload, or leave this step out until you have.
Daily use with an ssh config entry
Typing -i on every login is slow. Add a host entry to ~/.ssh/config on your laptop:
Host myvps
HostName 203.0.113.10
User alice
IdentityFile ~/.ssh/id_vps_primary_sk
IdentitiesOnly yesssh myvps now uses the primary key. On the day you need the spare, run ssh -i ~/.ssh/id_vps_spare_sk myvps, or use the file ssh-keygen -K wrote on a new computer.
What to do when you lose a security key
Act on the same day. Log in with the spare, then list the fingerprints in authorized_keys:
ssh-keygen -lf ~/.ssh/authorized_keysEach line shows a fingerprint and the comment you gave the key, such as vps primary. Delete the lost key's line with an editor, then enrol a new primary and add it as before, with the verify-required prefix. Until you do, you are back to one key, which is the situation this whole setup avoids.
If both keys are gone, use the provider console. Log in with the password, add a new security key's public line to authorized_keys, and test it from a new terminal. The PubkeyAcceptedAlgorithms line does not need to change, because the new key is also a security key type.
FAQ
Does ed25519-sk work with my security key?
Only if the device supports Ed25519. Every FIDO token must implement ECDSA P-256, but Ed25519 hardware support is less common. On a YubiKey, Yubico says ed25519-sk needs firmware 5.2.3 or newer. If ssh-keygen -t ed25519-sk fails on your device, generate the key with -t ecdsa-sk instead. The server setup is the same, and its public line starts with sk-ecdsa-sha2-nistp256@openssh.com.
What happens if I lose my only security key?
You cannot log in with it again, because the secret lives only on the device and cannot be exported. The file on your laptop is just a handle. This is why you enrol a spare, add both public keys to authorized_keys, and test the spare before you tighten sshd. With no spare, your only way in is a provider console with a password login.
Does PubkeyAuthOptions verify-required block normal SSH keys?
No. The sshd_config manual says touch-required and verify-required have no effect on non-FIDO key types. An ordinary ssh-ed25519 key still logs in. To refuse ordinary keys, set PubkeyAcceptedAlgorithms to the security key types only, and delete the old keys from authorized_keys.
How do I use my FIDO2 SSH key on a new computer?
If you created it with -O resident, plug in the device, change to an empty directory and run ssh-keygen -K. It writes a public and a private key file into the current directory. Log in with ssh -i and the private file it wrote. A key created without -O resident cannot be downloaded this way, so you need a copy of its original handle file. On Windows, run ssh-keygen -K in an elevated administrator terminal.
Which OpenSSH version do I need for FIDO2 SSH keys?
OpenSSH 8.2 on both ends for ed25519-sk and ecdsa-sk keys. OpenSSH 8.4 on both ends for a PIN on every use with verify-required. The build must also include FIDO support, so test with ssh-keygen -t ed25519-sk rather than trusting ssh -V alone. Microsoft's Windows build supports FIDO from its 8.9 release. Apple's bundled ssh may not support it at all, while Homebrew's OpenSSH does.