Made Own YubiKey Less Than? DIY Security Key Guide
In this article
Yes, you can make your own security key that works like a YubiKey for less than the cost of a commercial one, typically $10-$20 in parts. However, it won't be a true YubiKey clone; it will be an open-source FIDO2/U2F authenticator that uses the same standards, so it works with most services that accept YubiKeys.
What a YubiKey Actually Does
A YubiKey is a hardware security key that uses the FIDO2 and U2F protocols to provide strong two-factor authentication (2FA). Instead of typing a six-digit code from an app, you plug in the key and tap it. The key holds a private key that never leaves the device. When you log in, the website sends a challenge, the key signs it with the private key, and the server verifies the signature using the public key it stored during registration. This is phishing-resistant because the signature is bound to the website's origin, so a fake login page can't replay it.
Commercial YubiKeys also support other functions like OTP (one-time passwords), OpenPGP, and PIV (smart card) for SSH and email encryption. A DIY key usually focuses on FIDO2/U2F only, which covers most online accounts (Google, GitHub, Microsoft, etc.).
Why Build Your Own?
The main reasons people build their own are cost, learning, and control. A single YubiKey 5 series costs $25-$55, and you often want two (one as a backup). A DIY key can be made for under $20 if you already have a soldering iron and a spare microcontroller. You also gain full control over the firmware, which appeals to privacy-conscious users who want to audit the code. Finally, building one is a great way to understand how hardware authentication works.
Hardware Options for DIY Keys
There are several popular microcontrollers that can run open-source FIDO2 firmware:
- Raspberry Pi Pico (RP2040) – costs about $4, has USB, and runs the open-source Pico-FIDO-2 project. It's the most common choice.
- ESP32 – supports Bluetooth and USB, but the FIDO2 implementation is less mature. It's better for wireless experiments.
- STM32 boards – more powerful, but require more setup and are overkill for a simple key.
- ATtiny85 – very cheap, but limited memory; only supports older U2F, not FIDO2.
You also need a USB connector (micro or USB-C) and a few passive components. Some boards have USB built-in, like the Pico, which simplifies the build.
Software and Firmware
The firmware is what makes the hardware speak FIDO2. The most mature open-source project is Pico-FIDO-2 by an individual developer. It supports FIDO2 and U2F, plus WebAuthn with PIN and biometrics (on the Pico). You compile it with the Pico SDK and flash it via the board's bootloader. Another option is SoloKey's open-source firmware, which runs on their own hardware but also supports some STM32 boards. The SoloKey project also sells kits, but you can buy the parts separately.
Flashing is done by holding the BOOTSEL button on the Pico and dragging a UF2 file onto the USB drive it appears as. After that, the key is ready to use. You can then register it with any FIDO2-compatible service.
Step-by-Step Build Guide
Here's a practical guide for a Raspberry Pi Pico build:
- Gather parts: Raspberry Pi Pico, a USB-A or USB-C breakout board, a button (optional, for touch), a 3D-printed case (optional), and a soldering iron.
- Clone the Pico-FIDO-2 repository and build the firmware using the Pico SDK. The README has exact commands.
- Hold the BOOTSEL button on the Pico and plug it into your computer. It appears as a USB drive.
- Copy the generated .uf2 file to that drive. The Pico reboots and now runs the FIDO2 firmware.
- If you added a button, wire it to a GPIO pin and configure the firmware to use it as the touch sensor.
- Test the key by registering it on a FIDO2 demo site like webauthn.io.
- Put the key in a case and use it as your daily 2FA device.
Cost Comparison: DIY vs. Commercial
Here's a rough cost breakdown (prices vary by region and time):
- Raspberry Pi Pico: $4-$6
- USB breakout board: $1-$3
- Button, wires, case: $2-$5
- Total DIY: $7-$14
- YubiKey 5 NFC: $25-$55
- SoloKey (commercial open-source): $20-$30
So you save about $10-$40 per key, but you spend several hours building and troubleshooting. If your time is valuable, buying a commercial key is often cheaper in the long run.
Limitations and Risks
A DIY key is not as polished as a commercial one. The firmware may not support all FIDO2 extensions (like HMAC-secret for certain password managers). It lacks NFC, which many phones use. It may not be as durable – a YubiKey is waterproof and crush-resistant, while a bare Pico is fragile. Also, you are responsible for your own security: if you lose the key and didn't set up a backup, you could be locked out of accounts. Finally, some services may not recognize the device as a security key and might block it if they have a vendor allowlist, though this is rare.
Frequently Asked Questions
Is a DIY YubiKey as secure as a real one?
For FIDO2/U2F, yes, the cryptographic security is identical because it uses the same public-key standards. The main risk is physical: a commercial key has tamper-resistant chips, while a DIY key's firmware could be read and cloned if someone steals it. However, for most personal use, the threat model is low.
Can I use a DIY key with my phone?
Only if your phone supports USB OTG and you have a USB-C or micro-USB adapter. There is no NFC support in the DIY firmware, so you can't tap it like a YubiKey NEO. For mobile use, you'd need a USB-C Pico variant or an adapter.
What if I lose my DIY key?
You should always set up a second factor method (like backup codes or another key) when you register a security key. If you lose it, you can use those backup methods to regain access. You cannot recover the private key from the device, so without a backup, you're locked out.
Does it work with Google, GitHub, and Microsoft?
Yes, any service that supports FIDO2/WebAuthn will work. Google, GitHub, Microsoft, and most password managers (like Bitwarden) accept standard FIDO2 keys. Some services require a specific vendor ID, but that's rare.
Can I use a DIY key for SSH or GPG?
Not with the default Pico-FIDO-2 firmware. It only does FIDO2. If you want SSH or GPG, you'd need a different project like SoloKey or a commercial key that supports OpenPGP and PIV.
How long does it take to build?
If you already have the parts and tools, about 1-2 hours including soldering and flashing. If you need to order parts and 3D print a case, add a few days for shipping.