Back to articles
Security & Anti-DDoS

Ultimate SSH Security: Guide to Configuring YubiKey FIDO2/U2F Hardware Authentication for VPS

Transitioning from traditional password-based SSH authentication to hardware-based authentication using YubiKey FIDO2/U2F significantly enhances VPS security by eliminating password...

DPTCloud Engineering5 min read
Ultimate SSH Security: Guide to Configuring YubiKey FIDO2/U2F Hardware Authentication for VPS

Image credit: analogicus · Pixabay Content License

Transitioning from traditional password-based SSH authentication to hardware-based authentication using YubiKey FIDO2/U2F significantly enhances VPS security by eliminating password scanning, brute-force attacks, and credential leaks. This guide provides a detailed, step-by-step implementation, covering server setup, OpenSSH configuration, successful authentication testing, and common troubleshooting. Suitable for enterprises and individual users seeking robust VPS protection based on modern open security standards.

Introduction to Hardware Authentication and YubiKey

Hardware-based authentication uses a physical device to verify user identity, moving beyond reliance on passwords. YubiKey is a widely supported hardware device that implements the FIDO2 and U2F standards, enabling strong authentication via the WebAuthn protocol. When used with SSH, YubiKey completely replaces passwords, offering significantly higher security than traditional password or SSH key authentication because the hardware device cannot be copied or remotely attacked.

YubiKey FIDO2/U2F operates by generating a unique digital signature on the device when the user presses the button. This signature is sent to the server and verified by the SSH system. Since no password is transmitted and no sensitive information is stored on the server, network attacks or phishing become nearly impossible. This guide focuses on configuring YubiKey FIDO2/U2F with SSH on a Linux VPS, using OpenSSH 8.2+ and common operating systems like Ubuntu 20.04/22.04 or CentOS 8.

Prerequisites and Initial Setup

To implement this configuration, you need:

  • A Linux VPS server (Ubuntu 20.04/22.04 or CentOS 8)
  • A YubiKey device supporting FIDO2 (YubiKey 5 Series or later)
  • An SSH client supporting FIDO2 (such as OpenSSH 8.2+ on the client machine)
  • SSH access to the server with root or sudo privileges

First, update the system and install the necessary packages:

sudo apt update && sudo apt upgrade -y
sudo apt install -y openssh-server libpam-u2f

For CentOS/RHEL, use:

sudo yum update -y
sudo yum install -y openssh-server pam_u2f

Ensure the OpenSSH server is configured to support PAM (Pluggable Authentication Modules) and that PAM-based authentication is enabled in the /etc/ssh/sshd_config file:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication yes
UsePAM yes

Restart the SSH service to apply the changes:

sudo systemctl restart sshd

Configuring FIDO2/U2F Authentication on the Server

To enable FIDO2/U2F authentication, you need to create a PAM configuration file for YubiKey. Create the /etc/pam.d/sshd file (if it doesn't exist) and add the following lines:

auth required pam_u2f.so cue authfile=/etc/u2f_keys debug
auth required pam_u2f.so cue authfile=/etc/u2f_keys debug

This is the basic PAM configuration. The /etc/u2f_keys file will store the registration information for the YubiKey for each user.

For users who want to use YubiKey authentication, you need to register the device. On the client machine, run:

ssh-keygen -t ed25519 -f ~/.ssh/yubikey_id
ssh-copy-id -i ~/.ssh/yubikey_id.pub user@your-vps-ip

This command creates an SSH key and copies it to the server. However, to register the YubiKey device for FIDO2 authentication, you must register it directly on the server. Run the following command as root:

sudo pamu2fcfg -u user -i /dev/hidraw0 -o /etc/u2f_keys

Replace user with the username and /dev/hidraw0 with the actual YubiKey device (you may need to verify the correct device). When prompted, press the button on the YubiKey to complete registration.

Testing and Troubleshooting

After configuration, test SSH login from the client machine:

ssh user@your-vps-ip

SSH will prompt you to press the button on the YubiKey. If login succeeds, authentication is correctly set up.

If you encounter issues, check the following:

  • Ensure OpenSSH server version is 8.2+ and supports PAM.
  • Verify the /etc/pam.d/sshd file has the correct configuration.
  • Ensure the YubiKey device is connected and properly recognized.
  • Check SSH logs: sudo journalctl -u sshd -n 50 for detailed error messages.
  • Confirm there are no PermitRootLogin yes or PasswordAuthentication yes entries in /etc/ssh/sshd_config.

If device registration fails, check USB device access permissions or try using the u2f-host command to verify connectivity.

For further information on SSH security and hardware authentication, refer to:

DPTCloud Tier III Infrastructure

Recommended NVMe Cloud VPS Plans to Deploy This Setup

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02

VPS-2E

94.600 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 2 GB
  • SSD: 30 GB NVMe
ECO · vn-02Recommended

VPS-3E

170.500 ₫ / mo

10% VAT included

  • CPU: 2 vCPU
  • RAM: 4 GB
  • SSD: 50 GB NVMe
BASIC · vn-01Recommended

VPS-05

457.600 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478