Live data from Hacker News

Ask HN: What are the best practises for using SSH keys?

news.ycombinator.com

1–10 of 114 posts

Ask HN: What are the best practises for using SSH keys?

#1
Following the recent post about upgrading SSH keys to ED25519, I am wondering what the best practises (regarding security) for using SSH keys are.

For example:

- Is it better to use a different passphrase on each key, or does using the same one not matter much?

- How much less secure is it to not use a passphrase on a key?

- Should you use a different key per user account, per server, or per use-case (i.e. personal or work)?

- Does increasing the amount of bits in a key really have an effect on the security of the key, or does it not make much difference in a real-world use?

- How/Where should private keys be stored on a device using them?

- What are some of the pros and cons from a security standpoint, and how may doing different things affect the usability of a key?

Re: Ask HN: What are the best practises for using SSH keys?

#2
- Is it better to use a different passphrase on each key, or does using the same one not matter much?

Yep in an ideal world, though I suspect in practice it doesn't matter much.

- How much less secure is it to not use a passphrase on a key?

You are relying completely on the security of your disk, against either physical or cyber. Use a passphrase, use an agent to manage it.

- Should you use a different key per user account, per server, or per use-case (i.e. personal or work)?

Per client device. This is the device that can be compromised and cause invalidation to be required, so this is the one which should be seperate. For convenience you can maintain all your devices public keys concatenated together and hand them out like that - comment each with hostname and date created for ease of identification.

- Does increasing the amount of bits in a key really have an effect on the security of the key, or does it not make much difference in a real-world use?

Up to a point. RSA in 8 bits is trivial. Go for a highish key length, different key types have different recommended lengths. Note some machines dont support higher lengths.

- How/Where should private keys be stored on a device using them?

In $home/.ssh

Permissions should be set for only you to read with no writing. Even better if your home drive is encrypted as it is only vulnerable whilst you are logged in.

- What are some of the pros and cons from a security standpoint, and how may doing different things affect the usability of a key?

If you hop machines a lot key per client can be problematic. In this case a portable secure drive is useful. Of course one leak can be fatal here.

Try not to fall back on passwords, they have nothing like the same security.

Most usability issues are caused by the people running the servers not reacting in a timely fashion to key updates.

Re: Ask HN: What are the best practises for using SSH keys?

#3
I consider best practice to be using a hardware token.

My favoured solution is to use a yubikey via gpg: with this method you use your gpg subkey as an ssh key. The yubikey 4 supports RSA 4096 bit keys, if you need NFC then the Yubikey Neo supports max RSA 2048 bit keys.

Re: Ask HN: What are the best practises for using SSH keys?

#5

- Is it better to use a different passphrase on each key, or does using the same one not matter much? Yep in an ideal world, though I suspect in practice it doesn't matter much. - How much less secure is it to not use a passphrase on a key? You are relying completely on the security of your disk, against either physical or cyber. Use a passphrase, use an agent to manage it. - Should you use a different key per user a…

If necessary, it's possible to fall back to password plus OTP.

That's a reasonable compromise, since you carry the OTP generator around with you.

Re: Ask HN: What are the best practises for using SSH keys?

#6
Some general advice based on most requirements.

- Is it better to use a different passphrase on each key, or does using the same one not matter much?

If they are being used on different device then different passphrases makes sense otherwise no.

- How much less secure is it to not use a passphrase on a key?

10? Not sure you can really quantify an answer. I'd recommend a passphrase if you aren't already using disk encryption with that it's probably less of a concern however with agents there's not much issue with not having one.

- Should you use a different key per user account, per server, or per use-case (i.e. personal or work)?

Use a different key per client device but you don't need a different key for logging into different servers unless you care about people correlating those users.

- Does increasing the amount of bits in a key really have an effect on the security of the key, or does it not make much difference in a real-world use?

Use more than 2048bit for RSA/DSA beyond that it doesn't matter.

- How/Where should private keys be stored on a device using them?

~/.ssh on some local filesystem.

Re: Ask HN: What are the best practises for using SSH keys?

#7

I agree with following comment.i was wrong. Thanks asdfaoeu for it.

> Private key is a "password", we need to treat it as such!

This is harmful advice in my opinion. A key has sufficient entropy to resist brute force attacks and is never directly exposed to a server. The same key between multiple servers is fine.

Re: Ask HN: What are the best practises for using SSH keys?

#9
> - Is it better to use a different passphrase on each key, or does using the same one not matter much?

It is better to use a different passphrase for each key but it is also less convenient unless you're using a password manager (personally, I'm using KeePass)

> - How much less secure is it to not use a passphrase on a key?

That depends on the security of the computer where the keys are. I remember a Firefox vulnerability where one site exploiting it was looking for ssh keys on the local file system. So I'd say that a passphrase is very important.

> - Should you use a different key per user account, per server, or per use-case (i.e. personal or work)?

Personally I'm using a key per account per host.

> - Does increasing the amount of bits in a key really have an effect on the security of the key, or does it not make much difference in a real-world use?

Yes up until 2048 where the returns of increasing the amount of bits will start diminishing.[1]

  [1]: https://www.gnupg.org/faq/gnupg-faq.html#no_default_of_rsa4096

Re: Ask HN: What are the best practises for using SSH keys?

#10

I consider best practice to be using a hardware token. My favoured solution is to use a yubikey via gpg: with this method you use your gpg subkey as an ssh key. The yubikey 4 supports RSA 4096 bit keys, if you need NFC then the Yubikey Neo supports max RSA 2048 bit keys.

This. It's so cheap and easy to use a hardware token for your GPG and SSH keys nowadays (YubiKey 4! TPM! Smartcards!). If you're not using one, you should.
Post reply on HN