So far I've created a separate SSH key for each server I need to login to (for each purpose, to be more accurate). I did it out of a sense of security, just like different passwords to different sites.

Does having multiple SSH keys actually improve security? All of them are used from the same machine, are located in the same ~/.ssh, most even have the same passphrase.

So... should I give up the whole system and just use one SSH key for everything?

[UPDATE 2015-08-05] Github publishes your public key, and your SSH client may send all of your public keys to every server, depending on configuration, thusly, if you are concerned with a 3rd party SSH server knowing your identity when connecting, you should use multiple SSH keys, though in my opinion it is paranoid.


6 Answers 6


SSH keys use public-key cryptography. That means that what you're installing on all those servers is just your public key, which you want the whole world to know. The only actual secret is your private key that you keep locked down on your own machine. So yeah, I'd say you're wasting your time.

  • 22
    I think there are valid reasons to have separate keys, and this would not be a waste of time. In the case of a compromised key, the risk with this is reduced. The password should be different for each key, I agree.
    – jfmessier
    Mar 18, 2010 at 16:19
  • 1
    Is it reasonable to have different keys pairs on different machines? Like different instances of VirtualBox OSes? Jul 20, 2017 at 9:42
  • 1
    This answer ignores the concept of defence in depth, because it places reliance on "your private key that you keep locked down on your own machine". Consider for example what happens if your laptop is stolen while (one of) your private key(s) is being used by ssh-agent. If you have multiple keys, then any that were still encrypted are safe. I wouldn't call that a waste of time. Jan 22, 2019 at 20:49
  • 1
    Although you technically can say that there is a gain, I agree with Spiff that it practically is useless. I think the real point here is that if one private key on your laptop is compromised, then is most likely your other keys are compromised too. But I guess you can always have multiple keys and claim "security due to obscurity" 😂
    – alaboudi
    Jul 6, 2020 at 18:59

Ultimately this is up to you. You need to evaluate your threat model. How likely is it that one of your keys is compromised? If one key is compromised, how likely is it that the other keys will be compromised? What are the consequences of your keys being compromised? What is the cost (including time) of managing multiple keys?

Considering factors such as these should help you decide if you really need separate keys. On my personal machines on my local network I usually don't bother with extra overhead in trying to manage multiple keys. However, outside of my network I would use different keys each with a unique passphrase. But that is just my personal opinion.

  • 9
    +1 for "evaluating the threat model". This is just the point.
    – sleske
    May 17, 2010 at 8:45
  • Most of the time the private and public keys are stored in the same path on your machine so I would think that in that case it makes almost no sense to use multiple keys, if one is compromised the others will most likely be compromised too. Of course you should still use a good password for the private key. Apr 7, 2022 at 9:50

No it is not a waste of time to use more than one key.

More diversity == less risk.

That statement of Spiff's is incorrect.

The point is the public key grants access to the private key holder and no one else.

The risk to be concerned about here is authentication. A rogue site forwards authentication requests to your agent task. If you use only one key, then even when only one key is loaded in your agent, all sites are open to the rogue.

This has nothing to do with the passphrases, you could have several keys with the same passphrase that would make no difference here. Because it is not the passphrase that is compromised.

The rogue forwards challenges to your agent and can connect to all sites for which you have keys loaded. With different keys, one key loaded -> one site at risk.

I say good for you, you picked other peoples privacy over your own laziness.

P.S. the moral of the story is be wary of agent forwarding

  • 2
    Suppose I generate three SSH keys, one for each of three servers I log in to regularly. One day, after I've already logged in to all three (meaning that ssh-agent has cached the passphrases for all three keys), then by your argument, if my ssh-agent becomes compromised, all three log ins are compromised. In such a case, having multiple SSH keys has not protected me. Have I understood you correctly?
    – user11574
    Apr 23, 2011 at 6:17
  • Hm but dont most setups just unlock all ssh key on login ? E.g. on Mac and Linux the keyring is unlocked when logging in which in turn loads the ssh keys ?! Apr 7, 2022 at 9:57

I think there is one good use-case for multiple public keys, and that's if you have private keys stored on computers in different areas of trust. So I generally keep one key that is my "work" key, and another that is my "home" key, simply because the private key for my "home" stuff is not stored on my work computer and vice versa.

  • Great answer, if you have different machines with different keys, perfect. If one (or multiple) machines all have the same keys, well, you're not protecting yourself from anything extra vs just having a single key. If one is compromised all the rest on that machine are as well.
    – xref
    Feb 2, 2016 at 20:53
  • Agreed that makes a lot more sense as opposed to multiple work ssh keys, In my case all work ssh keys are unlocked (with the keyring) and loaded when I log into MacOS .... so I do not see how multiple key pairs are useful here Apr 7, 2022 at 10:01

I think reasonable can be considered from two different angles: security and convenience.

When we create a SSH key pair, we are asked for providing a passphrase to add a more layer to protect the private-key, as following:

$ ssh-keygen -t rsa -b 4096 -C 'With_OR_Without_Passwd'
Generating public/private rsa key pair.
Enter file in which to save the key (/Your/HomeDir/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

Although there is an explicit prompt asking for passphrase, but some (or many) people still focus more on the information in brackets: (empty for no passphrase), and following that suggestion.

Combining whether or not using multiple SSH key pairs and whether or not enter additional passwd, we have at least four ways to go. And let's assume all key-pairs and the config file are stored in ~/.ssh/.

Now let't consider security first.

The following table gives a simple rank about security (larger number means more secure):

Security     Ways to go
   1         One   SSH key-pair  (NO passwd)
   1         Multi SSH key-pairs (NO passwd)
   2         One   SSH key-pair  (WITH passwd)
   2         Multi SSH key-pairs (WITH passwd) (SAME passwd)
   3         Multi SSH key-pairs (WITH passwd) (DIFF passwds)

Without passwd, if our system is intruded by someone, then the breaker can get all of our private-keys and config, also the authentication of remote servers. So in this situation, One key-pair and Multi key-pairs are the same. The most secure way is to use different passwds for different ssh key-pairs.

Then let't think about convenience.

But more key-pairs and more passwds also make our life less convenient, the following table gives a simple rank about security (larger number means more secure):

Convenient  Security  Ways to go
   5           1      One   SSH key-pair  (NO passwd)
   4           2      One   SSH key-pair  (WITH passwd)
   3           1      Multi SSH key-pairs (NO passwd)
   2           2      Multi SSH key-pairs (WITH passwd) (SAME passwd)
   1           3      Multi SSH key-pairs (WITH passwd) (DIFF passwds)

So, in general situation, if we have to trade off with security and convenience at the same time, we can multiply the two scores, and maybe One SSH key-pair (WITH passwd) is the good one to choose.


The more knowledgeable answers on this page seem to converge on the idea that this is a trade-off, with marginal increments in security for less simplicity and convenience.

One notable point along this spectrum is the idea of creating one key for personal use, and one for work. Create a new work key each time you change jobs.

That way, your personal life won't end up breaking the security for your work stuff, and some dumb old job you had years ago can't end up breaking security for you personally.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .