Linux Security·8 min read·

Protecting SSH with FIDO2 / U2F Hardware Keys on Linux

Eliminate credential theft by configuring OpenSSH hardware-backed ed25519-sk keys with mandatory touch verification and FIDO2 tokens.

NB

Netbay Cloud Team

Netbay Engineering

On this page

Traditional SSH keypairs (such as id_ed25519 or id_rsa) are stored as text files on the developer's laptop. Even when encrypted with a passphrase, the decrypted private key is loaded into memory by ssh-agent where sophisticated info-stealer malware or compromised development dependencies can exfiltrate it. Once a private key is copied by an adversary, they possess permanent access until the key is identified and revoked.

OpenSSH security key credentials (ed25519-sk and ecdsa-sk) completely solve private key theft by anchoring authentication in physical FIDO2 / U2F hardware security keys (such as YubiKeys or Nitrokeys). The private key never leaves the secure cryptographic element on the physical USB hardware token. Furthermore, the token enforces user presence: every single authentication request requires a physical tap on the key.

Expand
Hardware Security Keys
FIDO2 Hardware Key Authentication for SSH
FIDO2 Hardware Token SSH Authentication Handshake SSH Client ssh user@server FIDO2 Hardware Key Challenge sent to USB token Physical Touch User taps hardware button Hardware Signature Signed assertion returned Server Verification authorized_keys validates touch Malware on the client computer cannot authenticate without physical interaction on the token.

Generating FIDO2 Hardware-Backed SSH Keys

Insert your FIDO2 security token and generate an ed25519-sk keypair. We recommend enabling resident credentials (allowing you to discover keys on any new machine) and mandatory user verification (PIN verification):

bash
# Generate resident, PIN-protected FIDO2 key
ssh-keygen -t ed25519-sk -O resident -O verify-required -f ~/.ssh/id_ed25519_sk -C "admin-yubikey-primary"

# You will be prompted to enter your security key PIN and physically touch the key

This produces two files on your laptop:

  • id_ed25519_sk.pub: The public key containing your token identifier.
  • id_ed25519_sk: A small key handle stub that instructs ssh to interact with the USB token.

Enforcing FIDO2 Keys on the Server

On your production VPS, append the public key to ~/.ssh/authorized_keys:

bash
# Sample line in ~/.ssh/authorized_keys
sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29tAAAAI... admin-yubikey-primary

To enforce that the server rejects any connection where the user did not physically tap the key, prefix the authorized_keys entry with no-touch-required negation or configure /etc/ssh/sshd_config:

ini
# /etc/ssh/sshd_config
# Disallow legacy password and DSA/RSA keys
PasswordAuthentication no
PubkeyAcceptedAlgorithms +sk-ssh-ed25519@openssh.com

# Enforce hardware touch verification
PubkeyAuthOptions verify-required

Reload the daemon:

bash
sudo systemctl reload sshd

Public Key Cryptography Video

Learn how asymmetric cryptography and hardware-backed signing protocols protect identity:

Public Key Cryptography and Hardware Keys Explained
YouTube

Recovering Keys on a New Machine

Because we utilized -O resident, you do not need to copy key files when switching workstations. Simply plug in your USB key and extract your credentials into the local agent:

bash
# Discover resident credentials stored inside the hardware key
ssh-add -K

Protect mission-critical cloud instances with modern cryptographic authentication on Netbay at netbayhosts.in.

Keep reading

Follow along on a real VPS

Deploy Linux in under 60 seconds

These guides are written against Ubuntu, Debian, and RHEL-family images — the same ones on NetBay.

Deploy an instance