18 ms·
Guide to Using YubiKey for GPG and SSH
- goodoldneon 5y agoIs there a way to encrypt a file with a Yubikey? I want to encrypt a GitLab token in a file that can only be decrypted when I tap my Yuibkey. Maybe I’m just being dumb, but I haven’t found a straightforward way to do it
- lokedhs 5y agoWith GPG you typically use assymetric cryptography, so you would be using the public key of the recipient, so you don't need the yubikey for that. However, the yubikey can be used when decrypting the message later.
- psanford 5y agorage + age-plugin-yubikey: https://github.com/str4d/age-plugin-yubikey https://github.com/str4d/age-plugin-yubikey
- cuu508 5y agoCovered by the guide: see https://github.com/drduh/YubiKey-Guide#using-keys https://github.com/drduh/YubiKey-Guide#using-keys and look for "Encrypt a message to your own key". Also, sops (https://github.com/mozilla/sops https://github.com/mozilla/sops) works with gpg and so with Yubikeys.
- eknkc 5y agoI wanted to do it when I first got one. It is possible but weird and not in any way straightforward.
- baybal2 5y agoI want to renember, Yubikey stopped publishing their firmwares
- csdvrx 5y agoFor SSH, you can use cheaper FIDO2 hardware to split your key between a computer and say a Google USB titan key or similar. For Windows, you need to compile (cf https://gist.github.com/martelletto/6a7cf806c6433ac9ce71d66afb94d70e https://gist.github.com/martelletto/6a7cf806c6433ac9ce71d66a... ) then ssh-keygen -t ecdsa-sk For Linux, if you need to recompile: https://cloud.google.com/compute/docs/tutorials/ssh-with-sk https://cloud.google.com/compute/docs/tutorials/ssh-with-sk
- microtonal 5y agoOn modern Macs, you can also use the Secure Enclave for SSH private keys: https://github.com/maxgoedjen/secretive https://github.com/maxgoedjen/secretive
- vbezhenar 5y agoYou can use TPM on Intel PC for SSH as well. Seems a little bit hacky, but it should work.
- _wldu 5y agoYou should avoid ecdsa and use ed25519 instead. https://www.schneier.com/blog/archives/2007/11/the_strange_sto.html https://www.schneier.com/blog/archives/2007/11/the_strange_s...
- willis936 5y agoOpenSSL's ECDSA implementation does not use Dual_EC_DRBG. You can read about what is actually done to make ECDSA keys here. https://wiki.openssl.org/index.php/Creating_an_OpenSSL_Engine_to_use_indigenous_ECDH_ECDSA_and_HASH_Algorithms https://wiki.openssl.org/index.php/Creating_an_OpenSSL_Engin...
- tptacek 5y agoNone of this has anything to do with ECDSA. Dual_EC_DRBG is a random number generator, not a signature algorithm.
- 5y ago
- pokstad 5y agoGreat guide. There more great docs and tooling here: https://gitlab.com/ayufan/yubikey-provisioner https://gitlab.com/ayufan/yubikey-provisioner
- sam_lowry_ 5y agoayufan is everywhere. When does he sleep?
- xvector 5y agoI disagree with the recommended key generation flow in this guide. I think the private key should be generated on-device, so it can never be extracted without faulting the YubiKey hardware. I also disagree with the idea of backing up the private key. Generating secure passwords is hard and it is infeasible to ask people to use diceware to generate and store their secure backup. And if you aren't doing backups you might as well generate the key on device. For the purpose of revocation, you can keep a signed revocation certificate around in the event you lose your key. This makes the guide much simpler, as you don't have to spin up a live airgapped system with secure boot for each employee's key generation. There's no need to have a complicated backup flow either. --- YubiKeys in general are problematic as they don't have a display that can show the action being taken, e.g. a compromised host could display one thing while the user is signing/encrypting another. This isn't a problem in modern crypto hardware wallets, which have displays that show precisely what is being signed, to mitigate this exact threat model.
- 3np 5y agoDo you have another one to recommend looking at? (I already own a Ledger Nano X and a Trezor in case that’s what you mean with “crypto device” and find the GPG experience insufficient).
- xvector 5y agoUnfortunately it does not look like the security key industry has caught up to the hardware wallet industry. Unlike a YubiKey, the screen on both Trezor and Ledger mitigate the confused deputy/phishing attack for the purposes of FIDO U2F. I'd recommend them with usage for U2F, specifically the Ledger if you're interested in better hardware security at the expense of open-source.
- 3np 5y agoI’ve tried both. Unfortunately the U2F as well as the PGP are clearly afterthoughts on these devices - the key management is lacking (doesn’t tie in well with the recovery phrase otherwise used for crypto assets) and the UX is cumbersome. I can overlook the UX issues when it’s a matter of 1-10 average signs per day and not 100s, like I have with PGP+U2F. I guess they’re all right as backup devices. The new Nitrokeys look interesting (and not yet available) but I agree, something is missing in the market here.
- miguelrochefort 5y agoCan this be used to decrypt files without exposing the private key?
- stavros 5y agoYes.
- stavros 5y agoThis is unnecessarily complicated to do for SSH, since SSH (and the Yubikey) support FIDO2: https://www.stavros.io/posts/u2f-fido2-with-ssh/ https://www.stavros.io/posts/u2f-fido2-with-ssh/
- vifon 5y agoNot every Yubikey supports the resident keys. All my Yubikey 5 keys have too old firmware, which AFAIK cannot be updated, so this is not a viable solution for lots of people even if they own the hardware. GPG just works, and can be used for many other things while one's at it already.
- stavros 5y agoI agree with you in general, but saying "GPG just works" in a post about a long guide on how to set it up seems iffy.
- markstos 5y agoNot just a little iffy, it's more like "Nope, even if I get this working, this is not something I can recommend supporting for everyone on the team." For business, it's a better deal to buy new Yubikeys that support FIDO2 then it is to support GPG on Yubikeys.
- Freak_NL 5y agoAbsolutely. We're trialling this for our SSH bastion server. The security keys don't need any setup at all, which makes it much easier to handle backups and replacements.
- vifon 5y agoLet me rephrase: GPG is possible to get working, the resident keys are not, regardless of the amount of setup. Though the other comment seems to suggest it might not be the case, so maybe there is hope.
- 5y ago
- sdn90 5y agoAnyone know if its possible to use a Yubikey for sudo as well?
- stingraycharles 5y agoYes, you’ll want the PAM module; either yubico-pam or pam-u2f. https://developers.yubico.com/pam-u2f/ https://developers.yubico.com/pam-u2f/ https://developers.yubico.com/yubico-pam/ https://developers.yubico.com/yubico-pam/
- cominous 5y agoYes it's possible ( https://www.ha-obsession.net/2017/05/u2f-sudo-fedora-25.html?m=1 https://www.ha-obsession.net/2017/05/u2f-sudo-fedora-25.html... and some other guides exists ) and I used it for about a year. I stopped using it. I was so annoyed to plugin the key every couple of hours that I simply kept the yubi key plugged in all the time - free to be picked by anyone and def. not increasing security. We still use it for SSH and its great!
- mrb 5y agoLeave the yubikey plugged in all the time. It's fine with respect to most threat models, provided you lock the graphical session when you are away from the computer. If someone steals the key, they can't really do anything with it. They can't sudo because the session is locked. They can't use it to log in your web accounts from other computers because websites ask for a password/pin in addition to touching the yubikey. PS: you should always have a backup yubikey (or, better, two)
- withinboredom 5y agoYou can also set the yubikey to require a pin before touching. The yubikey auto wipes it’s memory of the presented pin is wrong too many times in a row. So just leaving it plugged in is much more sensible in that case.
- Sporktacular 5y agoCould someone explain, all hardware based around FIDO2 and U2F standards is equally compatible with software right? Put another way, Yubikey, Solokeys and others based on those standard should be equally compatible with gmail, SSH, VeraCrypt, sudo etc. and so interchangeable, is that correct? It all appears to be pretty far from being plug and play, often seeming to require a lot of additional software/modules to get specific things working. Is this because the standards don't go far enough or am I just way off the mark?
- mlac 5y agoThe FIDO2 two factor auth portion is pretty seamless. It’s plug into USB port when the two factor prompt comes up, it will light up, touch the button, and good to go. Everything else - good luck. Proprietary apps. Each one is slightly different. I haven’t bothered to use it for key generation. To be fair, there are hardware design constraints (no clear UI) so it would be hard to get around the learning curve.
- Sporktacular 5y agoOkay, sorry if this is obvious. So FIDO is intended for authentication on the web/cloud only (and requires compatibility from both the website/site and the browser to work). So this is why when talking about using hardware keys to unlock local stuff, like a PC, or authenticate/decrypt SSH, GPG, bitlocker etc. this all gets so tricky and often needs extra software?
- mlac 5y agoI’m by no means an expert in this area (and expect someone here could speak to it better than I can), but the Yubikeys have a lot of capability. From their website: “Support for WebAuthn, FIDO2, FIDO U2F, smart card (PIV), Yubico OTP, OpenPGP, OATH-TOTP, OATH-HOTP, and Challenge-Response” [1] So one key can do all of those things. How user friendly it is depends on the service you’re using and how that is configured. Logging into to a google account? Easy. Logging into Windows? Easy-Medium [2]. As more organizations support the tool, it becomes plug and play in a lot of areas (Okta, centrify, etc). Mac is more difficult with opportunity to lock yourself out [5]. Linux is… Linux. You can set more configurable options in the manager tool. [3] But it can get as complicated as you want it to with the developer tools [4]. I’ve been following this for years and have had keys, and I think we’re finally to the point where I could recommend it to a semi-technical person. Get 3 - 1 small form factor that stays in your main computer / pc / chromebook, one on your key ring with NFC, and a backup in a fireproof safe. That will stop any account takeover. If a key is lost or stolen, revoke and replace it. That will cover 99% of attack scenarios for the population. [1] https://www.yubico.com/product/yubikey-5-nfc/ https://www.yubico.com/product/yubikey-5-nfc/ [2] https://www.yubico.com/products/computer-login-tools/ https://www.yubico.com/products/computer-login-tools/ [3] https://www.yubico.com/support/download/yubikey-manager/ https://www.yubico.com/support/download/yubikey-manager/ [4] https://www.yubico.com/support/download/ https://www.yubico.com/support/download/ [5] https://support.yubico.com/hc/en-us/articles/360016649059-Using-Your-YubiKey-as-a-Smart-Card-in-macOS https://support.yubico.com/hc/en-us/articles/360016649059-Us...
- lifeisstillgood 5y agoSilly question: (I have been meaning to dive deeper on this but ...) If I am in a small company, I can give everyone a yubikey and have some process that verifies everyone. Now I want to eliminate cookies / sessions keys. (just go with me). I want to use client certificates - but I only trust the yubikey. I am noodling ways that I can generate client certs, install them fairly easily and sign them with the yubikey. The goal here is that client certs are a really good idea- every request can include one, as opposed to every request including a session cookie / nonce that is open to interception / playback etc etc. And now we have billions of hardware security modules (am including secure enclaves in phones) - so there really ought to be a way through here. My problems include "generating client certs client side" - not something many browsers support and signing that in some sensible fashion But is all seems quiet possible
- zie 5y agoGive up on TLS client certs. The UI for client certs in browsers are miserable, terrible, horrible and insert every other awful adjective you can imagine. Seriously, it's so broken as to be unusable. Everybody knows it, nobody wants to fix it.
- anonymousDan 5y agoInteresting - can you give some specific examples of the major UI problems?
- zie 5y agoThe scars still haven't healed. ;) see: https://textslashplain.com/2020/05/04/client-certificate-authentication/ https://textslashplain.com/2020/05/04/client-certificate-aut...
- lifeisstillgood 5y agoBut it is the right way. With a client certificate the end server knows, you don't need to fuck around with cookies and TLS binding and so on. Add a new end point - great to use that during your "session". it just works. One day I will work it out.
- m3nu 5y agoJust discovered that macOS supports Yubikeys in PKCS11 mode natively now. So no extra libs, like OpenSC needed and it works very stable (no repeated PIN requests). Lib and config line in .ssh/config is just: `PKCS11Provider /usr/lib/ssh-keychain.dylib`
- Avamander 5y agoIt's very similar with pcsc-lite on Linux if you want to use PIV instead of GPG or FIDO2.
- fdr 5y agoI used this set-up for about a year. It was fine, I even used it on Windows, Mac, and Linux. I found that you'd definitely have to know way more about the principles of the ssh-agent system and smartcards (and GPG's need for a long exclusive lock on the card to cache safely) once in a while to avoid getting stuck, especially since other parts of the operating system or, on Windows, multiple usable implementations of SSH (e.g. one via MSYS, one on win32/native, one in WSL1, or one in WSL2) may be involved. Learning this on Windows was especially "fun." This kind of knowledge is proximate to my own line of work, but I think it could be frustrating for others that have no such alignment. These days I use the FIDO support. It is much simpler, but software support is a bit on the bleeding edge. You don't get to amortize a GPG toolchain in for commit signing or anything like that, though.
- jwr 5y agoI have been using this setup for about three years now and it works very, very well. It's useful for GnuPG (so, encrypted backups), SSH and 2FA for multiple websites. I highly recommend this setup. I also recommend doing what I did: get two Yubikeys, not one. Do everything twice, that way you have a physical backup/fallback device. You can also choose to leave one permanently stored somewhere and carry another one with you. Encrypt your backups for two public keys, add two 2FA keys to critical sites, etc. It buys you lots of options for relatively little effort.
- egberts1 5y agoNice details. Too bad that there is no flow diagrams of how all physical object connects. Or key objects relates to each entity being transitioned. It’s a lot of reading and typing as you go before something clicks in one’s head.