Hardware-backed SSH keys
This page describes how to create SSH keys backed by secure hardware and use them for production access to WMF systems. We currently support hardware security keys based on the FIDO standard, such as a YubiKey.
Setting up a FIDO key on a Yubikey
A FIDO-backed key has two parts:
- The key file on disk (the key handle) is loaded into your SSH agent like a classic key, and its public key goes into Puppet.
- A secret on the token that cannot be copied off it.
Neither part works alone, which means a stolen SSH key file is not enough to log in and each login needs a tap on the token.
OpenSSH supports this natively, and uses the libfido2 library to talk to the token.
Prerequisites
You need a FIDO-compatible security key. If you are a WMF staff member, you can reach out to ITS to obtain one. The following keys are known to be compatible and have been shipped by ITS in the past:
- YubiKey 5 (various models)
- YubiKey Security Key
Since FIDO is a standard, there's also plenty of other options. Compatibility can be checked at https://fidoalliance.org/certification/fido-certified-products/
For SRE we require two physical keys one for daily use and the other being a spare kept in a safe place.
For everyone else one physical key is sufficient. If you lose your only key, you lose production access until a new key is added to Puppet. We thus recommend having two physical key as for SREs.
OpenSSH 8.9 or later is recommended. FIDO support was added in OpenSSH 8.2.
- On macOS
- install OpenSSH from Homebrew (see step 1);
- On Windows
- the OS supports FIDO already, skip straight to step 3.
Network devices (routers, switches and firewalls) still use classic SSH keys. See #Access to network devices.
Instructions
1. Install required software
Installing on Linux
If you use a Yubikey, install the Yubikey manager package, which is named yubikey-manager on Debian/Ubuntu, Fedora, and Arch Linux (ykman on Homebrew). Example:
sudo apt install yubikey-manager
This is not necessary on Windows, which includes the necessary software. For macOS, see below.
Installing on macOS
The OpenSSH that ships with macOS does not support FIDO keys. Install OpenSSH from Homebrew, and use its ssh-agent.
First, install the required packages:
brew install openssh ykman
exec zsh # or exec bash
which ssh ssh-keygen ssh-agent ssh-add ykman # all /opt/homebrew/bin/
ssh -V must say OpenSSL, not LibreSSL.
If you are seeing /usr/bin then the system-provided binaries are prioritized because Homebrew is further in the PATH. Add
eval "$(/opt/homebrew/bin/brew shellenv)"to ~/.zshrc (or ~/.zprofile or ~/.bashrc) to fix this. [1]
Alternatively, if you want to use Homebrew just for SSH-related commands, Yubikey, and brew update and brew upgrade use this instead:
export PATH="/opt/homebrew/opt/openssh/bin:$PATH"
alias ykman="/opt/homebrew/bin/ykman"
alias brew="/opt/homebrew/bin/brew"Next, set up the agent socket. Add the following to your ~/.zshrc file (or similar, e.g. ~/.bashrc):
export SSH_AUTH_SOCK="$HOME/.ssh/agent.sock"
ssh-add -l >/dev/null 2>&1
if [ $? -eq 2 ]; then
rm -f "$SSH_AUTH_SOCK"
/opt/homebrew/bin/ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
fi
Then source ~/.zshrc (or similar).
Finally, OpenSSH does not support the UseKeychain keyword. Add the following line to the top of ~/.ssh/config to suppress the warning:
IgnoreUnknown UseKeychain
2. Set FIDO PIN
For our use of FIDO SSH tokens, the PIN isn't used. Still it makes sense to change the PIN towards a custom one away from the factory default. Your PIN can be from 4 to 61 characters long. Run
ykman fido access change-pin
This is not necessary on Windows, you may instead be prompted to set up a PIN when using the Yubikey for the first time.
3. Generate new SSH key pair(s)
This step depends on the capabilities of your FIDO token. Run ykman info to get information about your Yubikey (or see Identifying your Yubikey).
If you have a Yubikey 5 or different modern FIDO key, connect it to your computer. Generate a new key pair and attestation files by executing the script below.
If you have an older Yubikey, it may not support the ed25519-sk key type. This includes Yubikey 4 series and Yubikey 5 series with firmware older than 5.2.3. You may see the error FIDO_ERR_UNSUPPORTED_ALGORITHM when attempting to generate the key. If you do, re-run the command, replacing ed25519-sk with ecdsa-sk.
You will be required to touch the security key when its light starts flashing. Your SSH tool may indicate "Confirm user presence for key ED25519-SK SHA256:..." if so. Note that you may not get an explicit prompt on the command line, though, and then you must touch it before it times out in order for the key to be generated properly. If it does time out, you may see an erroneous message asking for your PIN. In this case, quit and re-run the command, and touch the security key when the light starts flashing, before it times out.
You will then be prompted for the filename to use for your key. It is best to use a name you can associate with the physical device, especially if you have multiple Yubikeys. For example yubi_primary and yubi_spare so you can tell them apart.
Next you will be prompted for a passphrase. With a FIDO-backed key, adding a passphrase to the key handle part of your key is significantly less important compared to a traditional SSH, but it still makes sense to add a passphrase as defense in depth. The passphrase will only be requested once when you load it into your SSH agent.
Run the script after having filed LOGIN (login name for ssh connection) and COMMENT (freeform description of the ssh key pair, must be unique among your key pairs).
The script will create four files on your local computer:
- A public key which can be added to 'authorized-keys' on remote systems as before
- A private key, which is the key handle to your FIDO token
- A
<LOGIN>_challenge_<COMMENT>.binfile. - A
<LOGIN>_attestation_<COMMENT>.binfile.
# login name used for WMF production
LOGIN=
# Descriptive name of your token which will be appended as a comment
# to the public part of your key
COMMENT=
export LOGIN COMMENT
head -c 128 /dev/urandom > ./"${LOGIN}_challenge_${COMMENT}.bin" \
&& ssh-keygen -t ed25519-sk \
-O challenge="${LOGIN}_challenge_${COMMENT}.bin" \
-O write-attestation="${LOGIN}_attestation_${COMMENT}.bin" \
-C "${COMMENT}"
Repeat these steps for your spare key. Connect only one key at a time.
On Windows
Run these commands in PowerShell instead. You'll get GUI prompts to insert and tap the hardware key. Everything else is as above. (replace USERNAME with your username on production, and TOKEN-NAME with a descriptive name of your token which will be appended to the public part of your key)
$out = New-Object byte[](128)
$rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($out)
[System.IO.File]::WriteAllBytes('USERNAME_challenge_TOKEN-NAME.bin', $out)
ssh-keygen -t ed25519-sk -O challenge=USERNAME_challenge_TOKEN-NAME.bin -O write-attestation=USERNAME_attestation_TOKEN-NAME.bin -C TOKEN-NAME
If it complains that Unsupported certificate option "challenge=USERNAME_challenge_TOKEN_NAME.bin", then you will likely require newer OpenSSH, installable with winget install Microsoft.OpenSSH.Preview then located at C:\Program Files\OpenSSH\ssh-keygen.exe
You may also find the alternative version for PowerShell at https://phabricator.wikimedia.org/P97043 useful.
If the last step complains that 'ssh-keygen' is not recognized..., you might need to enable support by going to Settings → Optional features → Add → OpenSSH Client.
If the last step fails with some other error (e.g. Key enrollment failed: unexpected internal error), you may have an older version of OpenSSH installed as part of the Git for Windows package. Run where ssh-keygen and check that the first (or only) line of the result is C:\Windows\System32\OpenSSH\ssh-keygen.exe; if it isn't, go to Settings → Environmental variables and tweak your PATH variable so that this directory is present and at the top of the list.
4. Upload challenge and attestation files
In order for your key to be validated, the challenge and attestation files must be uploaded via SSH key attestation metadata upload form .
5. Add the public keys to puppet repo for production access
Now the public key(s) generated in step 3 need to be registered in the Wikimedia Puppet repository (which ensures that the key is installed to the authorized_keys of the Wikimedia servers you can access).
If your request is part of the October 2026 migration effort, please update your assigned group task and skip creating a separate task.
If you do not yet have production access, see SRE/Production access and follow the instructions to request access.
Otherwise, to replace your existing SSH keys with the new, hardware-backed keys, open a task in Phabricator and add the SRE-Access-Requests tag. There's a rotation of SREs handling the tickets.
Example: T439665, gerrit 1346423
If you are familiar with the Wikimedia Puppet repository you can also go ahead and prepare a patch with your key change. The YAML file in question is modules/admin/data/data.yaml, search for your username and add your new key to the ssh_keys: field.
When adding multiple keys it makes sense to have a description after each that helps identify it. That makes it simpler to remove one of them in the future if a particular key is lost/damaged.
6. Configure SSH
You can use the wmf-laptop SSH client config as a template. Replace USERNAME and PRODUCTION_KEY with your values, and add one IdentityFile line for each key. Its IdentityAgent lines point to an agent socket that wmf-laptop starts with systemd (/run/user/1000/…). On macOS and other systems without that agent, remove those lines, so that your normal agent is used.
Or use this minimal config. Replace USERNAME, and set HostName to the bastion closest to you:
Host bast
HostName bast1004.wikimedia.org
User USERNAME
IdentityFile ~/.ssh/yubi_primary
IdentityFile ~/.ssh/yubi_spare
IdentitiesOnly yes
ControlMaster auto
ControlPath ~/.ssh/control-%C
ControlPersist 10m
Host *.wmnet
ProxyJump bast
User USERNAME
IdentityFile ~/.ssh/yubi_primary
IdentityFile ~/.ssh/yubi_spare
IdentitiesOnly yes
If a Host * block lists an old key with IdentityFile, SSH tries that key first on every host, even with IdentitiesOnly yes. Remove it from Host *, or an old key that is still in Puppet can log in without a tap.
Every connection goes through a bastion host, so the first connection needs two taps: one for the bastion and one for the target host. With either config, later connections reuse the bastion connection and need one tap. See #I need to tap my token twice for every connection attempt.
Using Windows-backed security keys from WSL
When using Linux OpenSSH inside WSL2 with a security key connected to Windows, you can use the Windows OpenSSH FIDO helper. Add the following to your WSL ~/.bashrc (or the equivalent configuration for your shell):
export SSH_SK_HELPER="/mnt/c/Program Files/OpenSSH/ssh-sk-helper.exe"
Open a new shell, and check:
test -x "$SSH_SK_HELPER" && echo "helper found"
7. Test each Yubikey
With each Yubikey plugged in, one at a time, try the following. The commands use the bast host from the minimal config in step 5. Replace HOST.eqiad.wmnet with a production host you have access to:
ssh-add ~/.ssh/yubi_primary ~/.ssh/yubi_spare
ssh bast -O exit 2>/dev/null # Closes a shared connection, if you use ControlPath.
ssh HOST.eqiad.wmnet true # expect 2 taps
Only one tap means one hop used another key, usually an old key. To see which key each hop used:
ssh -v -o ControlPath=none bast true 2>&1 | grep 'Server accepts key' ssh -v HOST.eqiad.wmnet true 2>&1 | grep 'Server accepts key'
8. Complete the migration by removing your old SSH key(s)
Once your tests are complete and you're happy with the new setup, you can reopen the Phabricator task that added your key and request the deletion of your old non-FIDO key.
Example: T439665, gerrit 1346424
Tips and tricks
Getting Desktop notifications that a touch might be required
If you are running a Debian Trixie and later system, you can get easy notifications on your window manager using libnotify and yubikey-touch-detector. The following assumes that $XDG_CONFIG_HOME=$HOME/.config, adjust accordingly.
apt install yubikey-touch-detector
mkdir $HOME/.config/yubikey-touch-detector/
cp /usr/share/doc/yubikey-touch-detector/examples/service.conf.example $HOME/.config/yubikey-touch-detector/service.conf
systemctl --user enable --now yubikey-touch-detector.service
Feel free to edit the config file if needed, but the defaults are pretty sane.
Special cases
Access to network devices
FIDO isn't supported in the OpenSSH version of all our network devices yet, or in some libraries Homer relies on such as Paramiko. As such we'll remain using classic SSH keys for now (SSH access to network devices is managed via the Homer repository, instead of Puppet). You can use the following config snippet in ~/.ssh/config to configure a different key for accessing the network devices:
Host cr* lsw* asw* msw* mr* cloudsw* ssw* fasw* pfw* User USERNAME IdentityFile ~/.ssh/YOUR_NON_FIDO_KEY ProxyCommand ssh -a -W %h:%p BASTION
Replace USERNAME, YOUR_NON_FIDO_KEY and BASTION (e.g. bast1004.wikimedia.org) with your own values. SSH does not expand $USER-style variables in these settings.
The public key should be added under 'users' in common.yaml in the homer public repo.
Non-standard key types
ssh-keygen defaults to keys which are stored on the FIDO token with a key handle stored on disk (and what is also used for accessing Wikimedia systems). There are additional possible key types which can be generated by passing an option during ssh-keygen, which are not in use when accessing Wikimedia systems:
- The verify-required option requires the user to enter their FIDO PIN every time they connect to a remote host. While this adds an additional layer of security, it would be too cumbersome for day-to-day SSH access (but it might be an option for some systems with elevated sensitivity in a later step).
- If the resident option is used, the key handle is also stored on the FIDO token. This makes it easier to use the token on multiple computers, but someone who steals the token then potentially has both parts of the key (it is still protected by PIN). This isn't a setup that is supported for accessing Wikimedia systems.
Troubleshooting
I need to tap my token twice for every connection attempt
SSH access to Wikimedia is routed via so-called bastion hosts (these servers are named bast*).
Every SSH connection to a production host other than the bastion hosts goes via two SSH connections:
- A connection to the configured bastion host over the internet
- A second connection through that bastion session to the destination server
If this is done in the simplest way then every time you connect to a remote host it will require two presses of the FIDO token, one for each of these connections. This can be confusing; while the token will blink twice, there's usually no other indication of needing to tap a second time.
There is however an OpenSSH feature which mostly avoids this: SSH Multiplexing allows the reuse of an existing TCP connection for multiple SSH sessions, which means that:
- The first SSH connection (often also called the master connection) will require tapping twice.
- As long as one SSH connection is open (or if ControlPersist is used, see below), all further connections will reuse the TCP connection and only require a token tap for the connection to the target server.
The following configuration settings are required to make use of SSH multiplexing:
- The connection to the bastions needs to enable a SSH multiplexing by configuring a ControlMaster (setting it to auto is the recommended setting)
- The connection to the bastions needs to configure a ControlPath (which is the socket used for connection multiplexing)
- (Optional) If ControlPersist is set to a time frame (e.g. 60m), then the master connection will remain open in the background and avoid the need to double-tap if you have only made one SSH connection and closed it before opening a new one.
Our default SSH client config as provided by wmf-laptop already uses SSH multiplexing. As an example, however, the below shows the specific commands that are used to ensure SSH multiplexing and proxying work:
Host bast1004.wikimedia.org
ControlMaster auto
ControlPath ~/.ssh/control-%C
ControlPersist 10m
IdentitiesOnly yes
IdentityFile ~/.ssh/yubi_colour
IdentityFile ~/.ssh/yubi_black
ProxyCommand none
Host *.eqiad.wmnet
IdentitiesOnly yes
IdentityFile ~/.ssh/yubi_colour
IdentityFile ~/.ssh/yubi_black
ProxyCommand ssh -a -W %h:%p bast1004.wikimedia.org
Most production hosts are under *.wmnet. Add a similar block for each data centre and its bastion, as the wmf-laptop config does.
Post-quantum key exchange warning
After updating OpenSSH (e.g. from the version that ships with macOS, to the bleeding edge from Homebrew), you'll get the following warning when connecting to Gerrit or any other production host over SSH:
** WARNING: connection is not using a post-quantum key exchange algorithm.
** This session may be vulnerable to "store now, decrypt later" attacks.
** The server may need to be upgraded. See https://openssh.com/pq.html
This warning can be ignored and unfortunately be shown every day going forward. See also T407557 (production) and T407844 (Gerrit). You can optionally hide this warning in your ~/.ssh/config file as follows:
# https://wikitech.wikimedia.org/wiki/Production_shell_access#SSH_configuration
Host *.wikimedia.org,*.wmnet
# https://phabricator.wikimedia.org/T407844
WarnWeakCrypto=no-pq-kex
Host gerrit.wikimedia.org
# https://phabricator.wikimedia.org/T407844
WarnWeakCrypto=no-pq-kex
Project operations/debs/wmf-sre-laptop not found
wmf-sre-laptop (master)$ git fetch origin fatal: project operations/debs/wmf-sre-laptop not found fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
This repository was renamed last year (T365985). Re-clone from the description at https://gerrit.wikimedia.org/g/operations/debs/wmf-laptop/, or update your existing checkout as follows:
git remote set-url origin https://gerrit.wikimedia.org/r/operations/debs/wmf-laptop
References / background
A few useful references with more background:
- The original announcement by the OpenSSH developers with some background: https://www.openssh.com/txt/release-8.2
- The complete guide to SSH with FIDO2 - Jonas Markström
- Official documentation