Skip to content

Use FIDO2 Security Keys for SSH Authentication

Admin
October 5, 2026
9 min read
Intermediate
💻 Target OS: Ubuntu 24.04+ / Debian 12+

Before you begin

  • Applies to:OpenSSH key authentication using a FIDO2 security key.
  • Where to start:Start on the client with the security key connected. Keep an approved fallback session or server console available.
  • What you need:Have a compatible key and OpenSSH setup, an authorized test account, and a way to verify the new login before changing existing access.
Guide tools
Guide tools
0/0 Steps (0%)

OpenSSH security-key credentials (ecdsa-sk or ed25519-sk) use a FIDO authenticator to sign SSH challenges. The local .pub file is public; the local private-key handle is still needed, while the signing secret remains on the authenticator. A copied handle alone cannot authenticate without the registered hardware key.

A touch proves user presence. Requiring a PIN or biometric adds authenticator user verification, but SSH security-key login is not automatically multi-factor authentication in every policy or threat model. It does not protect a compromised client or replace host-key verification. This guide requires touch and user verification, uses two separately enrolled keys, and only then disables password-based SSH login.


01

Confirm the Client Supports Security-Key Algorithms

Client Preparation

Use an OpenSSH client with FIDO security-key support and an authenticator that supports user verification. Check for an sk- key algorithm before creating a credential. Win32 OpenSSH support is available in version 8.9.0.0 and later; no vendor key-manager application is required for OpenSSH authentication.

Terminal window
ssh -V
ssh -Q key | grep -E '^([email protected]|[email protected])$'
❯ Illustrative Output (Results Vary)

02

Generate a Primary Key and a Backup-Key Credential

Authenticator Setup

Use a separate FIDO authenticator for the backup. Generate a credential for each device and protect each local key-handle file with a passphrase and appropriate file permissions. Keep the existing administrator session open while setting up and testing both credentials. If your authenticator cannot perform user verification, the verify-required option will fail; use a supported authenticator rather than removing the server requirement.

Terminal window
mkdir -p ~/.ssh && chmod 700 ~/.ssh
for key in ~/.ssh/id_ecdsa_sk_primary ~/.ssh/id_ecdsa_sk_primary.pub ~/.ssh/id_ecdsa_sk_backup ~/.ssh/id_ecdsa_sk_backup.pub; do
if [[ -e "$key" ]]; then
printf 'Key file already exists; choose new paths to avoid replacing credentials: %s\n' "$key" >&2
exit 1
fi
done
ssh-keygen -t ecdsa-sk -O verify-required -f ~/.ssh/id_ecdsa_sk_primary -C "admin-primary-key" || exit 1
ssh-keygen -t ecdsa-sk -O verify-required -f ~/.ssh/id_ecdsa_sk_backup -C "admin-backup-key" || exit 1
chmod 600 ~/.ssh/id_ecdsa_sk_primary ~/.ssh/id_ecdsa_sk_backup || exit 1
❯ Illustrative Output (Results Vary)
Generating public/private ecdsa-sk key pair.
Enter PIN for authenticator:
You may need to touch your authenticator to authorize key generation.
Your identification has been saved in .../id_ecdsa_sk_primary
Your public key has been saved in .../id_ecdsa_sk_primary.pub

03

Install Both Public Keys and Verify New Sessions

Access Validation

Add both public keys to the target account while the current administrative session remains open. Use the matching client commands below, then connect once with each authenticator and confirm the PIN or biometric and touch prompt succeeds. Do not continue until both credentials work and you have a separate recovery path approved by your organization.

Terminal window
cat ~/.ssh/id_ecdsa_sk_primary.pub | ssh [email protected] 'set -eu; umask 077; mkdir -p ~/.ssh; chmod 700 ~/.ssh; touch ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys; IFS= read -r key || exit 1; case "$key" in [email protected]*) ;; *) exit 1 ;; esac; if grep -qxF "$key" ~/.ssh/authorized_keys; then exit 0; else status=$?; [ "$status" -eq 1 ] || exit "$status"; fi; printf "%s\n" "$key" >> ~/.ssh/authorized_keys'
cat ~/.ssh/id_ecdsa_sk_backup.pub | ssh [email protected] 'set -eu; umask 077; mkdir -p ~/.ssh; chmod 700 ~/.ssh; touch ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys; IFS= read -r key || exit 1; case "$key" in [email protected]*) ;; *) exit 1 ;; esac; if grep -qxF "$key" ~/.ssh/authorized_keys; then exit 0; else status=$?; [ "$status" -eq 1 ] || exit "$status"; fi; printf "%s\n" "$key" >> ~/.ssh/authorized_keys'
# Test each key in a separate new session; the second command uses the backup authenticator.
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ecdsa_sk_primary [email protected]
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ecdsa_sk_backup [email protected]
❯ Illustrative Output (Results Vary)
Authenticated with ecdsa-sk key; user verification and touch completed.
Keep the original administrator session open until both test logins succeed.

04

Restrict Accepted Keys and Require User Verification

Server Hardening

Confirm your server’s OpenSSH version supports these directives and that every SSH-enabled account that must retain access has both keys enrolled. These directives have global server scope: they accept only OpenSSH security-key algorithms, require user presence and verification, and disable password and keyboard-interactive authentication for every SSH account. Check the effective values with sshd -T -C for every relevant account and client context. Replace the example user, client host, and address in the command below; if effective values differ, resolve configuration include or Match precedence before reloading. Keep your current session and an out-of-band recovery route available while applying the change.

Terminal window
sudo install -d -m 0755 /etc/ssh/sshd_config.d || exit 1
if sudo test -e /etc/ssh/sshd_config.d/99-security-key-only.conf; then
printf 'Config file already exists; inspect and back it up before changing it.\n' >&2
exit 1
fi
sudo tee /etc/ssh/sshd_config.d/99-security-key-only.conf >/dev/null <<'EOF' || exit 1
PubkeyAcceptedAlgorithms [email protected],[email protected]
PubkeyAuthOptions touch-required,verify-required
AuthenticationMethods publickey
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
# Validate syntax and inspect the effective global settings before reloading.
sudo sshd -t || exit 1
sudo sshd -T | grep -E '^(pubkeyacceptedalgorithms|pubkeyauthoptions|authenticationmethods|passwordauthentication|kbdinteractiveauthentication) ' || exit 1
sudo sshd -T -C user=admin,host=client.example.com,addr=192.0.2.10 | grep -E '^(pubkeyacceptedalgorithms|pubkeyauthoptions|authenticationmethods|passwordauthentication|kbdinteractiveauthentication) ' || exit 1
❯ Illustrative Output (Results Vary)
pubkeyacceptedalgorithms [email protected],[email protected]
pubkeyauthoptions touch-required,verify-required
authenticationmethods publickey
passwordauthentication no
kbdinteractiveauthentication no

Choose the service name for your distribution, then reload the daemon:

Terminal window
sudo systemctl reload ssh || exit 1

05

Open Fresh Sessions with Both Keys

Final Verification

From a second terminal, open a new session with the primary key and then the backup key. Confirm that each requires the intended verification and touch. Only close the original session after both logins succeed and the recovery path is confirmed. Repeat the review for every account affected by the server-wide policy.

Terminal window
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ecdsa_sk_primary [email protected]
ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ecdsa_sk_backup [email protected]
❯ Illustrative Output (Results Vary)
Both newly opened sessions authenticated with their separately enrolled security keys.
Password and keyboard-interactive SSH authentication are disabled by the effective server policy.

Comments