Most tutorials for setting up SSH recommend generating the keypair on a client machine. Why exactly is this?

Assuming your communication lines are not compromised, and you delete the private key from the server after acquiring it, is it safe to generate the keys on a remote host?

  • 1
    When you generate an SSH key using the AWS control panel, it does exactly what you say. – paj28 Jul 29 '16 at 6:53

Because most guides are written for people who are not experienced and it is assumed to be safer (by reducing possibilities for mistake) to prevent the private keys from being transmitted/stored outside of the client on which they were generated. ssh-keygen command also automatically sets the limited permissions to the generated private key reducing the number of steps required.

Where you generate the keys and how you distribute them depends solely on the process (in the "management process"-sense). As long as you do not the compromise security by using an insecure generator or an insecure channel, the exact place where you generate the key pair does not matter. It might as well be a third machine.

  • 1
    Thank you for clearing that up. For me it usually is a third machine (maybe virtual), just because it's so easy to generate keys on linux, and my desktops usually are Windows. – Amani Kilumanga Jul 29 '16 at 7:39

Just guessing here, but keys depend on randomness and most servers don't have great sources of entropy. Entropy often comes from mouse movements and typing on the keyboard, things found on clients.

  • 2
    Please don't guess. Entropy also comes from disk and interrupt timings, and servers have plenty of those. – Sjoerd Jul 29 '16 at 7:34
  • Plenty of those? Really? You might find this of interest then: blackhat.com/docs/us-15/materials/… "Even without doing 'crypto' there is constant pressure on the entropy pool due to OS activities" What's worse than guessing? Asserting something as true, when it's not. – Swashbuckler Jul 29 '16 at 12:53
  • 1
    @Swashbuckler And even worse is relying on self-serving treatises as actual facts. – MAP Jul 30 '16 at 2:58
  • @Swashbuckler The authors of the slides you referenced (from 29 onwards) make a mistake of likening entropy_avail counter with an outbound entropy pool, when it's in fact the inbound pool (see this answer). Their conclusions regarding the entropy consumption are thus flawed (they even seem to admit it "[results] not consistent, still doing research" and "entropy use is not well understood"). – techraf Aug 1 '16 at 6:43

If you only have one client and one server and you are fully in control of both of them, it doesn't really matter where you generate the keypair. But if any of those assumptions are false, then it starts to matter.

I believe the "best" way to use your SSH keypair is to generate one keypair per client, and push that keypair's public key to all the servers that client is allowed to access. In other words, the client is the "trusted" computer and the servers are the leaf nodes the trusted computer is allowed to access (e.g. if you have a laptop and a desktop and a tablet, and each of those are allowed access to some servers, each of those servers will have 1-3 keys in their .authorized_keys files, indicating which of your laptop, desktop and tablet are allowed to access them; this allows you to revoke access (by deleting lines from .authorized_keys) if you lose control over one of the clients).

But if you generated your keypair on a leaf node, you are allowing any spyware (or anyone with access to your files) on that leaf node to gain access to all the other leaf nodes.

and you delete the private key from the server after acquiring it

What makes you think there isn't a process on the server that will store a copy of that private key before you can delete it? I'm not trying to pick on you, but you're making assumptions ("no one will look at files I create until after I log out"; "files I create won't be logged and won't persist after I delete them"; "passwords I enter won't be logged") that may not be accurate.

  • I think you might have misread my question a little. I'm not really making assumptions as much as I am asking if it is safe to make those assumptions. Thank you for the input. – Amani Kilumanga Jul 29 '16 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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