Information Security Stack Exchange is a question and answer site for information security professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it better to create a separate ssh-key for each host and user or just using the id_rsa key for all host to authenticate? Could one id_rsa be a malpractice for the privacy/anonymity policies?


having one ssh-key for all hosts:


in comparison to separate ssh-keys:

... etc.
share|improve this question
related: "Reusing Private/Public Keys" – David Cary Sep 22 '14 at 22:12
up vote 55 down vote accepted

A private key corresponds to a single "identity" for a given user, whatever that means to you. If, to you, an "identity" is a single person, or a single person on a single machine, or perhaps a single instance of an application running on a single machine. The level of granularity is up to you.

As far as security is concerned, you don't compromise your key in any way by using it to log in on a machine (as you would by using a password), so having separate keys for separate destinations doesn't make you any more safe from an authentication/security perspective.

Though having the same key authorized for multiple machines does prove that the same key-holder has access to both machines from a forensic perspective. Typically that's not an issue, but it's worth pointing out.

Also, the more places a single key is authorized, the more valuable that key becomes. If that key gets compromised, more targets are put at risk.

Also, the more places the private key is stored (say, your work computer, your laptop, and your backup storage, for example), the more places there are for an attacker to go to grab a copy. So that's worth considering as well.

As for universally-applicable guidelines on how to run your security: there are none. The more additional security you add, the more convenience you give up. The one piece of advice I can give categorically is this: keep your private key encrypted. The added security there is pretty significant.

share|improve this answer
Thank you for so rich answer! Do you know a good article about private key encryption? Does this fit enough […? – static Aug 5 '13 at 13:43
That'll do; similar information here. Use ssh-keygen -p to re-encrypt existing keys. (Docs) – tylerl Aug 5 '13 at 16:58
"so having separate keys for separate destinations doesn't make you any more safe from an authentication/security perspective" isn't that like saying "using separate passwords for your website logins isn't more secure than using a different password for each website"? – SpaghettiCat Jun 7 at 7:53
PastaFeline, I would think the key difference (see what I did there?) is that the secret bits (the private key) for SSH never leave the client machine, while the secret bits (the password) or a hash of them are transmitted to the remote machine for password auth. If a user's password is weak it's vulnerable to brute-force cracking (see Rainbow Tables) even if all you have is the hash. – Scott Jun 7 at 19:48
@SpaghettiCat no, what I'm saying is that using a single ssh key across multiple destinations does not give any one destination enough information to impersonate you to any of the others. – tylerl Jun 7 at 19:55

What is the best practice: separate ssh-key per host and user VS one ssh-key for all hosts?

I dont know if i got your question right what do you mean by "key"? are you referring to asymmetric crypto?

when using asymmetric crypto you have a private and public key pair. The public key of each user is stored on the ssh-server (host). This allows to authenticate the user because for each public key there should be only one private key.

enter image description here

what do you mean by having one ssh-key for all hosts?

share|improve this answer
I already saw the image, but I'm interesting in details of the transition from step "Remote SSH server configured with "Public Key"" to "Private and Public Key Pairs MATCHED?" – static Aug 4 '13 at 23:20
if you are just interested in the transition from "Remote SSH server configured with "Public Key"" to "Private and Public Key Pairs MATCHED?" then take a look this – enigma Aug 4 '13 at 23:30

you only need one key as the key belongs to the user.

There is no need (and no improvement in security) by having one key per host.

As long as you private key is kept private you can go with this single key and use it to authenticate yourself against multiple hosts.

share|improve this answer
This is wrong. Using the same key to login to 2 servers/accounts reveals that both users are probably the same person. – Navin Nov 10 '15 at 20:24

The main benefit of separate keys is what happens in the worst-case scenario: someone gets your private key.

  1. SAME key on all hosts: The bad guys now have access to everything.
  2. DIFFERENT key on each host: The bad guys only have access to one thing.

So--most secure? Unique keys for each host.

share|improve this answer
If the attacker has access to the folder from the question, not only he has access to your private key, but also a list of usernames and hosts those keys work with – German Rumm Jun 23 at 0:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.