10 ms·
Spoiler: the default SSH RSA key format uses straight MD5 to derive the AES key used to encrypt your RSA private key, which means it's lightning fast to crack (
by tptacek 8y ago
Spoiler: the default SSH RSA key format uses straight MD5 to derive the AES key used to encrypt your RSA private key, which means it's lightning fast to crack (it's "salted", if you want to use that term, with a random IV).
The argument LVH makes here ("worse than plaintext") is that because you have to type that password regularly, it's apt to be one of those important passwords you keep in your brain's resident set and derive variants of for different applications. And SSH is basically doing something close to storing it in plaintext. His argument is that the password is probably more important than what it protects. Maybe that's not the case for you.
I just think it's batshit that OpenSSH's default is so bad. At the very least: you might as well just not use passwords if you're going to accept that default. If you use curve keys, you get a better (bcrypt) format.
While I have you here...
Before you contemplate any elaborate new plan to improve the protection of your SSH keys, consider that long-lived SSH credentials are an anti-pattern. If you set up an SSH CA, you can issue time-limited short-term credentials that won't sit on your filesystems and backups for all time waiting to leak access to your servers.
- X-Istence 8y agoIs there an openssl command to translate the old key format to the new key format while keeping the same RSA key which works with OpenSSH?
- tptacek 8y agoI think ssh-keygen -p -o -f (oldfile) should do the trick.
- lima 8y agoAnd/or use a smartcard to store your SSH keys. With YubiKey 4 being as cheap as they are, there's little excuses :-)
- tptacek 8y agoThis is what I meant by "elaborate new plans". I like Y4's as much as the next nerd, but if you're going to put that kind of energy in, spend the energy on setting up an SSH CA.
- knorker 8y agoOne does not exclude the other. If it did then a hardware token like Yubikey easily beats a CA.
- deleted 8y ago[deleted]
- lvh 8y agoHow does it "easily beat" a CA? It's still a long-held credential that you now have to manage across a fleet instead of a single SSH CA. You can get that short-term credential via a long-held key; that long-held key can even live on a Yubikey if you use U2F/WebAuthn. You get all of the security and usability benefits of U2F/WebAuthn as well as the off-boarding/on-boarding/compliance benefits of tying everything to SSO as well as the audit benefits of an SSH CA.
- knorker 8y agoYou can work around not having a CA, by distributing keys. I'm exaggerating when I say "just write a script", but it's not hard. You cannot work around not having hardware keys. SSH CAs improve efficiency and convenience. A hardware key that requires touch per login is a game-changer. When you go do lunch you know that your key did nothing, no matter how compromised your workstation is. When your machine is turned off you know that there's no copy of the key somewhere. That key cannot be used. A software cert-based key may be valid for only hours (if you set it up that way), but that means that there are 7 billion possible attackers who could use your key. They could break into your workstation and wait for the screensaver to kick in, and then log in to every single host you have access to, and do their naughty business. For a hardware key someone has to take a plane from China and break into your house to use your key. > It's still a long-held credential Doesn't have to be. But if it is, so what? Given physical locks that are unpickable and keys uncopyable, would you rather instead change locks every day, where the keys are copyable? (even if cost of changing locks scales O(1) with price) > that long-held key can even live on a Yubikey if you use U2F/WebAuthn Like I said, one does not exclude the other. You can't prove that A is better than B by saying A+B is better than B. There's also devices that don't support SSH certificates (e.g. embedded devices), but supporting pubkeys is vastly more common.
- unit91 8y ago> there's little excuses Yikes that statement has a lot of moral overtones. Is it a good idea to use a Yubi? Arguably yes. Does one need to find "excuses" for not doing so? The vast majority of the time, no.
- lima 8y agoNo moral overtones intended, the point being that the low cost and the form factor significantly lowers the barrier to entry. I've been using a GPG smart card for a long time, and it required a separate card reader, and both card and reader were easy to break. A YubiKey 4 fits on a keychain, is hard to break (though some of my colleagues succeeded) and you just plug it in.
- amaccuish 8y agoI like my smartcards. Bummed they didn't catch on. How do you feel about losing the PIN and using a password? I like how, if I'm at my desk using a hardware PIN pad, it's much less likely i'll have problems.
- lima 8y agoFor SSH, it's fine. The hardware PIN pad does not show which server I'm logging into, so it adds little extra security.
- Latty 8y agoI think the intent was more that security keys greatly reduce the friction associated with more secure practices, reducing the reasons to use less secure ones.
- jacobvosmaer 8y agoThe user experience of doing this is very bad. Every time I look into doing this I end up with blog posts that describe punching numbers into the GPG CLI, master keys, subkeys, PIN's. I don't want to be a GPG enthusiast, I just want to use my SSH key safely. (No offense to GPG enthusiasts!)
- yayana 8y agoI found an X509 oriented device relatively easy for ssh (for gpg it is naturally harder to use these non gpg devices with some kind of bridge daemon). Assuming Linux or OsX where your distribution has an opensc that already supports your device, ssh is only about 3 incantations of magic: https://nilsschneider.net/2013/06/20/epass2003-quickstart.html https://nilsschneider.net/2013/06/20/epass2003-quickstart.ht... But there is no safe way of getting away from having 1 pin.
- acdha 8y agoOn current versions of macOS it’s built in so all you need is to generate the key and add one line to your SSH config: PKCS11Provider=/usr/lib/ssh-keychain.dylib https://support.apple.com/en-us/HT208372 https://support.apple.com/en-us/HT208372
- amaccuish 8y agoI dislike GPG as well, but I have the OpenPGP smartcard. I've just loaded it with x509 certs. There's OpenSC so I can use it in a browser/VPN/SSH/Apple Mail etc.
- fragmede 8y agoThat's a side effect of the GPG being the back end technology that the Yubikey-based SSH keys are based on. If you don't want to have to learn gpg (because why should you?) the master/sub keys, PINs, keyservers, and all that can be dumped, just like ssh-keygen is able to create keys without passphrases - not exactly recommended, but still better than the alternative.
- 8y ago
- mfontani 8y agoI've not been able to find a good tutorial on how to store keys, plural, on a Yubikey 4 or any other smartcards. They're all limited to storing one, maybe two "authentication" GPG keys. Would you have some pointers?
- lvh 8y agoThat’s right: the number of keys you can store on it is limited. That’s one of the reasons we think you should just use them for identity, not temporary authorization.
- cperciva 8y agoSpoiler: the default SSH RSA key format uses straight MD5 to derive the AES key used to encrypt your RSA private key, which means it's lightning fast to crack (it's "salted", if you want to use that term, with a random IV). Indeed, I pointed this out in my May 2009 talk about scrypt (http://www.daemonology.net/papers/scrypt-slides.pdf http://www.daemonology.net/papers/scrypt-slides.pdf). There were even OpenSSH developers in the room!
- lvh 8y agoAnd a mere four years later they added a format that uses bcrypt... in a PBKDF2 construction? (I haven't found a motivation why, though Ted Unangst's post on it just says "I know about scrypt".)
- tedunangst 8y agoScrypt is "excessively parameterized." ;)
- dijit 8y agoI don't mean to sound stupid; but I am, so it comes out that way. What does this mean? Does it mean it's hard to use, or easy to mess up or something else?
- aw1621107 8y agoMy first guess would be that it has "too many parameters/knobs". I guess that could implicitly mean it's hard to use/easy to mess up if you don't know what each parameter means and what different values have.
- user5994461 8y agoI guess the same. Not sure why the downvote. The latest crypto functions expect the developer to pick parameters for the memory usage, the time to run and god knows what. Too low and it's worse than MD5, too high and your login prompt takes a whole minute to check the password.
- tedunangst 8y agoI think the explanation for most bad defaults in ssh is "redhat" which is kinda insane but I very much stay out of that sandbox. The default can't be changed until existing systems can read the new keys. So like 2028 or something.
- irrational 8y agoWhy can't it be fixed and then just break for Redhat (until Redhat rolls out fixes/patches)?
- detaro 8y agoFor the key storage format, not the key type, wouldn't that only be a problem where you copied a key to a redhat system? Requiring conversion there doesn't sound too bad?
- cbhl 8y agoYou're basically asking a "you broke my workflow" kind of question. https://xkcd.com/1172/ https://xkcd.com/1172/ In high school, I definitely kept password-protected private keys on a USB key that got plugged into whatever machine happened to be available. (Now I am affluent enough to carry around a real Security Key and a trusted laptop.) If you were the maintainer, would you really want to change the defaults and deal with the backlash of complaints from users who do copy keys around?
- jessaustin 8y agoEven the OpenSSH people will tell you not to copy private keys around. Non-ephemeral private keys should be generated where they will be used. You can copy the public key...
- Dylan16807 8y agoOkay I generated a key on a computer that I will only be using for the next 3 hours, and may never see again. How do I install it? Is that method actually more secure than carrying around an encrypted key?
- sneak 8y agoThe KDF used for password-based symmetric encryption (gpg -c, private keys on disk) in GnuPG is also terrible - but at least it is an iterated KDF of a fast function, as opposed to one-shot. I would happily put up funds for a bounty to fix the default in GnuPG but I don’t know where to post/fund such a thing.
- mrrandomguy11 8y agoYou would have to change the OpenPGP standard - other implementations would have to follow that.
- sneak 8y agoThe iteration count is serialized into the message.
- old-gregg 8y ago> consider that long-lived SSH credentials are an anti-pattern. Exactly. Consider switching to auto-expiring SSH certificates. You can build your own certificate management using a few open tools or switch to Teleport [1] which is 100% certificate based and doesn't even support keys. Disclaimer: I am one of the contributors. [1] https://github.com/gravitational/teleport https://github.com/gravitational/teleport
- nerdponx 8y agoThanks for this. I will happily check out your tool, but what are some of the other solutions in this area?
- lvh 8y agoThere’s also BLESS and Hashicorp Vault. I have a penchant for Teleport.
- pvg 8y agoOh! Teleport does look pretty decent now that I've forced myself to look at it after going through this thread. I mention this mostly for the sort of people like me who read 'SSH CA' and their eyes roll into the backs of their heads and they start rocking and making saliva bubbles at thought of PAM modules and LDAP servers and so on. But this doesn't look nearly as bad. Go ssh implementation sounds like a nice ancillary bonus.
- thenewwazoo 8y agoIt’s probably pretty rotted by now but I wrote a version of this while I worked at Microsoft called ALTAR that’s backed by Azure services.
- peterwwillis 8y agoI just went to the top 20 search results for "how do I generate ssh keys". Almost none of them use the defaults. Almost all of them suggest to use "-t rsa", and some with "-b 4096". The ones using defaults are from Joyent, SSH.Com, and git-scm.com. Since probably nobody is creating SSH keys without using a guide first, we should be able to get websites to update their guides with better default arguments, which will improve things going forward. Almost all the Windows guides suggest using PuTTYgen with defaults, which gives you a 1024 bit RSA key, and that might be worse in the long run than these password shenanigans.
- tptacek 8y ago"-t rsa" uses the same terrible format as the default.
- peterwwillis 8y agoI'm saying that since they mostly don't use defaults, it should be trivial to argue for a few extra arguments.
- bigfudge 8y agoWhat would that look like?
- wvh 8y ago-o, for the newer key format. Or use -t ed25519 to generate ed25519 (elliptic curve) keys. I do recollect that using RSA keys of 4096 bits slows down SSH more than the gain in security might be worth.
- lvh 8y agoLook, 2048 is fine. Assuming no algorithmic speeduos you get 112 bits of security and that’s plenty. But SSH keys are only used to sign: they don’t affect bulk encryption. 4096’s performance is not what’s holding you back.
- mmcclellan 8y agomonitoring thread for mentions of tooling. Seen teleport and vault - no mention yet of bless/blessclient yet.
- throwawaymath 8y agoWhy hasn't anyone done for OpenSSH what Jason Donenfeld did with Wireguard?
- pgeorgi 8y agouse wireguard with telnet/ftp bound to it
- e12e 8y agoI guess that should be wireguard with rsh.
- lvh 8y agoOxy is trying: https://github.com/oxy-secure/oxy https://github.com/oxy-secure/oxy But it’s important to remember that SSH is a lot less fucked overall than the VPN situation was. People mostly grok SSH. SSH mostly doesn’t negotiate BF-CBC.
- tptacek 8y agoI disagree! SSH is not great! Because it doesn't need to support every browser on the Internet, new crypto percolates through the ecosystem much faster than it does in TLS. But it's still a janky protocol with dumb options, and a Noise-based no-negotiation alternative that fulfilled the same interface would indeed be super useful.
- lvh 8y agoI don’t think we actually disagree; I said “a lot less fucked” not “great” :) you can get real AEADs with Ed25529 in SSH easily; and some of the dumb options problems may still apply with Oxy, depending on what you’re taking about.
- textmode 8y agoI have been using tinysshd for a number of years and I am hooked. Keen to experiment, I have also been using ed25519 keys instead of rsa since this option was added to openssh. No one told me to use tinysshd or ed25519 keys. As someone else pointed out, it seems like most "guides" on ssh, even ones written after ed25519 was added, still advocate rsa keys.
- baby 8y agoWould you say the "you don't need to migrate to Argon2" culture is actually a bad thing?
- lvh 8y agoI think I’m missing context. You don’t need to migrate from what? If you have reasonable scrypt or bcrypt I’m not gonna tell you to move.
- TheAceOfHearts 8y agoDo you have a guide for home users you could point to that provides clear guidelines for managing your SSH keys? I have a few home servers, but if one of my devices were compromised I don't think it would take much longer for the whole network to fall. I'd love an end-to-end example that shows how you're storing everything, in both meatspace and your devices. Do you use hardware authentication devices? How do you handle backups?
- lvh 8y agoIf you can put up with GPG cards, gpg-agent knows how to pretend to be an SSH auth socket meaning it can do your signing for you. At key generation time you can dump the key (once!) and then feed it to paperkey as a backup.
- chx 8y ago> consider that long-lived SSH credentials are an anti-pattern With due respect: have you considered the myriad systems where you need to upload your SSH key to an UI? If my key is short term then I need to do that all the time. I can't set up an SSH CA on github for example.
- alxlaz 8y agoThe fact that GitHub does it, too, doesn't make it any less of an anti-pattern.
- kalalala024 8y agohttp://www.prfree.org/news-watch-ufc-227-live-fight-569216.html http://www.prfree.org/news-watch-ufc-227-live-fight-569216.h... https://www.youtube.com/watch?v=MoNMIkUpXBw https://www.youtube.com/watch?v=MoNMIkUpXBw
- laumars 8y agoGitHub has APIs for automation (eg via Terraform). Granted not ever web-based service does, but if you were sufficiently determined to use SSH CA then I'm sure you'd find a way (or an alternative service that did support your workflow).
- lvh 8y agoYes, we mentioned GitHub repeaatedly in these threads.
- joelthelion 8y ago> consider that long-lived SSH credentials are an anti-pattern. I don't think that's necessarily true, provided that your keys are: - Properly encrypted - Protected by a decent password - You use ssh agent to avoid 1) copying the key everywhere, and 2) typing your password all the time. Of course it depends how critical security is. Access to a few dev servers inside the company firewall is not the same as managing your client-facing production infrastructure.
- otterley 8y agoOut of curiosity, how can you have individual user logins on a host while delegating authn/authz to a CA? All the examples I've seen thus far involve a shared login, whereas I find it's a lot easier to audit hosts when a unique user ID is in the logs, last/w/who output, etc.
- gdamjan1 8y agobless allows to specify the remote user in the certificate. you'll need to customize the certificate issuing program (a small python lambda program)
- otterley 8y agoI think I need some more information. What I'd like to do is to have a signed certificate that only lets me into the "otterley" account on the remote host, while not letting "jsmith" into my account (only hers) or vice versa. My understanding of CA principals is that they identify the user or role that requested the signing, but not necessarily the login ID on the server that is allowed to be logged into. Ideally there'd be a 1:1 mapping between the principal and the login ID on the server. I think there's some sshd configuration that needs to be done, but I haven't seen any clear instructions for doing so. Do you know how to accomplish this?
- e12e 8y agoHave a look at eg: https://linux-audit.com/granting-temporary-access-to-servers-using-signed-ssh-keys/ https://linux-audit.com/granting-temporary-access-to-servers... And re-read the (imnho rather obtuse) ssh-keygen man pages. [ed: and maybe this too: https://framkant.org/2017/07/scalable-access-control-using-openssh-certificates/ https://framkant.org/2017/07/scalable-access-control-using-o... ]
- otterley 8y agoThanks! So it looks like AuthorizedPrincipalsFile/AuthorizedPrincipalsCommand gives us a method for doing this. This would have to be combined with some sort of user ID management system still, like distribution of /etc/{passwd,group} files, LDAP/AD, etc.
- zaarn 8y agoI put my SSH keys inside KeepassXC (regular Keepass supports this via plugin). Way better encryption and it automatically manages the adding of keys to the ssh-agent. All my other SSH keys I don't have in there are plaintext on the disk. The ssh askpass is in userspace and easily spoofed, any local attacker could easily fish it out anyway. Full disk encryption at rest ought to be enough for most people.