In the previous article, we generated an SSH key that can't be copied. The private key is locked inside a YubiKey Bio, and every use requires your fingerprint. That's a very strong safeguard, but it has one weakness that isn't obvious at first glance: the server doesn't know about it.
By default, an SSH server will accept your new hardware key, but it will just as happily accept a password, a regular key from a file, or a hardware key used without fingerprint verification. An attacker won't bother taking on your YubiKey. They'll simply pick the weakest of the doors you've left open.
In this article, we'll close all the other doors. We'll configure an SSH server on AlmaLinux 10 / RHEL 10 to let in only users with an ecdsa-sk key, and only when that key confirms user verification. Because a mistake in this configuration can cut off access to the server, we'll do it in a lab with a snapshot, and we'll check every step before closing the emergency session.
Where will we be working?
The server will be the lab-alma10 machine from the KVM lab we built in the article Your Own IT Lab: How to Safely Test Configurations Before They Reach Production. The client will be your workstation, the computer you plug the YubiKey into and on which you generated the keys in the previous article.
Before you change anything, take a snapshot of the machine. It's our simplest way back:
virsh shutdown lab-alma10
You can check the machine's IP address on the lab network with:
virsh domifaddr lab-alma10
In the rest of this article, I use the example address 192.168.122.50 and the user emil. Replace them with your own values.
How does an SSH server decide who to let in?
When you connect to a server, sshd (the SSH server process) answers three questions.
The first: which login methods are allowed at all? SSH knows several methods: password (password), interactive prompts for passwords or codes (keyboard-interactive), keys (publickey), and on RHEL, Kerberos (gssapi-with-mic) by default as well. If any of them is enabled, it's a potential way in.
The second: which kinds of keys are accepted? Even if we allow only key-based login, the server may accept regular Ed25519, RSA or ECDSA keys stored in files. We want it to accept just one type: the hardware key sk-ecdsa-sha2-nistp256@openssh.com.
The third: what must the key itself confirm? Every signature produced by a hardware key carries flags that say whether the user touched the device and whether they passed verification, in our case with a fingerprint. The server can demand that the verification flag be set. If it's missing, the signature is rejected, even if the key is valid.
That third point matters more than it seems. The verify-required option set when generating a key is information for the client. Whether verification is actually required is decided by the server. In the previous article, I described how a key file downloaded from a YubiKey with ssh-keygen -K can lose this information. A requirement enforced on the server side doesn't have that problem.
The trap: which configuration file wins?
On RHEL 9 and 10, you don't change the SSH server configuration in the main /etc/ssh/sshd_config file, but in separate files in the /etc/ssh/sshd_config.d/ directory. Take a look:
ls -l /etc/ssh/sshd_config.d/
You'll see at least the 50-redhat.conf file. There may also be 01-permitrootlogin.conf, which the installer creates if you allowed root password login during installation.
Now the most important rule, and a counterintuitive one: sshd uses the first value it encounters for each setting. Later occurrences of the same keyword are ignored. Files from the sshd_config.d directory are read in alphabetical order, at the very beginning of the configuration.
In practice, this means that a 01-permitrootlogin.conf file containing PermitRootLogin yes beats any PermitRootLogin no written in the main file or in a file whose name starts with a higher number. That's why we'll save our configuration in a file called 00-fido-only.conf. The 00 prefix guarantees it's read first.
This has one more consequence. The 50-redhat.conf file includes RHEL's system-wide cryptographic policy, which defines, among other things, the allowed key types. Our key type setting is read earlier, so it's the one that takes effect. That's intended: we deliberately want to narrow the list to a single type, regardless of what the general policy allows.
Step 1: public keys onto the server before we close the doors
Order is crucial here. First we deliver the public keys and confirm they work. Only then do we disable the other login methods.
On your workstation, copy both public keys, the main one and the backup, to the server. At this stage the server still accepts passwords, so ssh-copy-id will ask for yours:
ssh-copy-id -i ~/.ssh/id_ecdsa_sk_bio.pub emil@192.168.122.50
ssh-copy-id -i ~/.ssh/id_ecdsa_sk_bio_backup.pub emil@192.168.122.50
Now test logging in with the hardware key:
ssh -i ~/.ssh/id_ecdsa_sk_bio -o IdentitiesOnly=yes emil@192.168.122.50
The IdentitiesOnly=yes option tells the client to use only the specified key. Without it, the client could quietly log in with another key from your ~/.ssh directory, and the test would prove nothing. The YubiKey should ask for your fingerprint. Repeat the test with the backup key.
It's also handy to add an entry to ~/.ssh/config on your workstation, so you don't have to pass the options every time:
Host lab
HostName 192.168.122.50
User emil
IdentityFile ~/.ssh/id_ecdsa_sk_bio
IdentityFile ~/.ssh/id_ecdsa_sk_bio_backup
IdentitiesOnly yes
From now on, ssh lab is enough.
You can also set the verification requirement for an individual key, in the ~/.ssh/authorized_keys file on the server. That's what the verify-required option placed before the key is for. In a moment we'll enforce the same thing server-wide, but the extra option in authorized_keys is a good safeguard in case someone changes the global configuration in the future. On the server, run:
cp -a ~/.ssh/authorized_keys ~/.ssh/authorized_keys.$(date +%F-%H%M)
sed -i Every line with a hardware key should now start with verify-required sk-ecdsa-sha2-nistp256@openssh.com. Log out and log back in to make sure the key still works after this change.
Step 2: prepare a way back
Before you change the server configuration, prepare for the situation where something goes wrong.
Open a second session with root privileges on the server (sudo -i) and don't close it until you've finished all the tests. Reloading the SSH configuration doesn't drop existing connections, so this session will stay active even if new logins stop working.
Also back up the configuration directory:
sudo cp -a /etc/ssh/sshd_config.d /root/sshd_config.d.$(date +%F-%H%M)
In the lab, you also have a snapshot and the machine's console, available from the host (virsh console lab-alma10 or the Console tab in Cockpit). On a real server, the equivalent is an out-of-band console such as IPMI, iDRAC, iLO or your cloud provider's console. Don't roll out this change on a server you can't reach by any means other than SSH.
Step 3: configuring the server
Now for the actual change. Create the 00-fido-only.conf file:
sudo tee /etc/ssh/sshd_config.d/00-fido-only.conf > /dev/null <<Each line has its own job, so let's go through them one by one.
AuthenticationMethods publickey is the most important lock. It tells the server that the only method that completes a login successfully is a public key. Even if password login or Kerberos was enabled in another file, this line means none of those methods is enough.
PubkeyAcceptedAlgorithms sk-ecdsa-sha2-nistp256@openssh.com narrows accepted keys to a single type. A regular Ed25519 key from a file will be rejected, even if it's listed in authorized_keys. Keep in mind that this setting also excludes ed25519-sk keys. If someone on your team uses those, add sk-ssh-ed25519@openssh.com after a comma.
PubkeyAuthOptions verify-required requires every signature to carry the user verification flag. A hardware key used without a fingerprint or PIN, with just a touch, will be rejected.
PasswordAuthentication no and KbdInteractiveAuthentication no disable password login. Formally, AuthenticationMethods has already blocked them, but disabling them explicitly means the server doesn't even offer these methods to the client. The configuration is also clearer for anyone who reviews it later.
PermitRootLogin no forbids logging in directly to the root account. Administrators log in to their own accounts and elevate privileges with sudo, which leaves a trail in the logs showing who performed each operation.
Step 4: check before you reload
A typo in the SSH configuration can prevent the server from starting after a restart. That's why we check the syntax first:
sudo sshd -t
No output at all means the configuration is valid. If an error appears, fix the file before moving on.
The second check is more important. The sshd -T command shows the effective configuration, meaning what the server will actually apply after taking all files and the first-value rule into account:
sudo sshd -T | grep -Ei Expected output:
permitrootlogin no
passwordauthentication no
kbdinteractiveauthentication no
pubkeyauthoptions verify-required
authenticationmethods publickey
pubkeyacceptedalgorithms sk-ecdsa-sha2-nistp256@openssh.com
The order of the lines may differ, but the values must match. If any of them is different, for example permitrootlogin yes, it means another file sets that value before yours. In that case, check which file is read before 00-fido-only.conf.
Once both checks pass, reload the server:
sudo systemctl reload sshd
A reload applies the new configuration to new connections. Your open sessions, including the emergency session, remain active.
Step 5: tests that actually prove something
Run all tests in a new terminal window on your workstation, without closing the emergency session on the server.
Positive test: hardware key with fingerprint.
ssh lab
The YubiKey should ask for your fingerprint, and you should be logged in. Repeat the test with the backup key:
ssh -i ~/.ssh/id_ecdsa_sk_bio_backup -o IdentitiesOnly=yes emil@192.168.122.50
Negative test: password.
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password,keyboard-interactive emil@192.168.122.50
The server shouldn't ask for a password at all. The expected result is Permission denied (publickey). In the parentheses, the server lists the methods it accepts. You see only publickey.
Negative test: a regular key from a file. If you have a regular key, for example ~/.ssh/id_ed25519, and it was previously added on the server, try logging in with it:
ssh -i ~/.ssh/id_ed25519 -o IdentitiesOnly=yes emil@192.168.122.50
The login should fail. You'll see why in the server logs, in your emergency session:
sudo journalctl -u sshd --since Look for an entry saying the key type isn't in PubkeyAcceptedAlgorithms. That's exactly the result we wanted.
It's also worth checking the sshd logs after the positive test. On a successful hardware key login, you'll see an Accepted publickey entry with the key type ECDSA-SK. If the server rejects a signature without user verification, the log will say the verification requirement wasn't met.
Only when all the tests give the expected results can you close the emergency session.
When something goes wrong
You can't log in, but the emergency session is open. Remove the configuration file and reload the server. You're back to the state before the change:
sudo rm /etc/ssh/sshd_config.d/00-fido-only.conf
sudo sshd -t && sudo systemctl reload sshd
The emergency session was closed. Log in through the machine's console: in the lab, virsh console lab-alma10 or the console in Cockpit; on a physical server, the out-of-band console. The console doesn't use SSH, so the new configuration doesn't apply to it. Then run the same commands as above.
Nothing helps. In the lab, restore the snapshot:
virsh destroy lab-alma10
virsh snapshot-revert lab-alma10 before-ssh-fido
virsh start lab-alma10
sshd -t reports Bad configuration option. Check the spelling of the keywords. In older guides you'll come across PubkeyAcceptedKeyTypes (the old name) or ChallengeResponseAuthentication (the old name for KbdInteractiveAuthentication). Newer OpenSSH versions usually accept them as aliases, but it's better to use the current names.
Hardware key login is rejected even though you place your finger. Check the reason in the server logs. If it's about user verification, make sure the key was generated with the -O verify-required option and that fingerprints are enrolled on the YubiKey. If it's about the key type, check that you're not trying to log in with an ed25519-sk key, which we excluded in PubkeyAcceptedAlgorithms.
Before you take this to production
The lab let us verify the mechanism. On real servers, there are three more things worth thinking through.
The first is service accounts. Ansible, CI/CD systems and backup scripts log in without a human, so they can't put a finger on a reader. The configuration from this article will lock them out. Such accounts can be given separate rules in a Match User or Match Group block, combined with restrictions on the addresses they can connect from. That's a topic for a separate article, but you need to keep it in mind before rolling out the change.
The second is a gradual rollout. Instead of enforcing the requirement for everyone at once, you can start with a single group of administrators by placing the same settings in a Match Group block. Before such a rollout, check man sshd_config to see which keywords are allowed inside a Match block.
The third is key loss. Every administrator should have a registered backup key, and the team should have a procedure for emergency access through an out-of-band console. Without it, a lost YubiKey isn't a security problem, it's an availability problem.
What have we achieved?
The server now accepts only one way to log in: an ecdsa-sk hardware key with confirmed user verification. Passwords, regular keys stored in files, and a hardware key used with just a touch will all be rejected. An attacker who takes over your computer won't find anything on it that would let them log in to the server. Someone who steals your YubiKey won't get in without your finger.
You've also learned a rule that applies to the entire SSH configuration on RHEL and often surprises experienced administrators: the first value wins, not the last. The sshd -T command tells you the truth about how the server is configured, regardless of what's written in the individual files.
Securing the login is only the beginning of hardening a server. In upcoming articles, we'll look at what happens after login: limiting privileges, auditing, and service accounts that have to work without human involvement.