Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have accounts on two machines: H1 and H2. I created ssh keys on H1 and installed it on S1. I can now ssh to S1 from H1. I want to do the same from H2. How do I install the ssh keys generated on H1 on H2?

share|improve this question
add comment

migrated from stackoverflow.com Sep 6 '11 at 15:42

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 5 down vote accepted

You need to copy your private keys from H1 to H2, if you want to use your private keys to be able to login from H2 to S1. When you at H1 do the commands:

H1$ ssh H2 mkdir ~/.ssh
H1$ scp  ~/.ssh/id_rsa ~/.ssh/id_dsa H2:~/.ssh/

Warning! This will delete and replace any private key you have at H2.

Or you can generate new private keys on H2 and install their public part on S1 with ssh-copy-id. In second case you will have two sets of keys; one is for H1-S1 login and second for H2-S1 login. There will be two public keys authorized at S1. And you will be able to revoke any of them or both.

share|improve this answer
2  
Copying a private key is really not a good idea. Having a single key at multiple locations 1. makes it more vulnerable, 2. increases risk that you lost control of all the locations, 3. does not allow you to disable access from just one location. From the security point of view you should generate a new key-pair on every location - the solution from Mu Qiao. –  pabouk Sep 4 '13 at 16:56
add comment

Use ssh-copy-id

SYNOPSIS

ssh-copy-id [-i [identity_file]] [user@]machine

DESCRIPTION

ssh-copy-id is a script that uses ssh to log into a remote machine and append the indicated identity file to that machine's ~/.ssh/authorized_keys file.

share|improve this answer
    
@I want to do ssh from H2 to S1. I want to transfer and install my private and public key from H1 to H2. Will this do that? –  Bruce Sep 6 '11 at 15:17
1  
@Bruce no, you need to regenerate the keys on h2 and use that command to copy your keys. Another approach is letting h1 and h2 share home directory. –  Mu Qiao Sep 6 '11 at 15:19
add comment

Would ssh-copy-id do the job for you: http://linux.die.net/man/1/ssh-copy-id?

share|improve this answer
    
@I want to do ssh from H2 to S1. I want to transfer and install my private and public key from H1 to H2. Will this do that? –  Bruce Sep 6 '11 at 15:16
1  
If you are logged in to either S1 or H1 (which now have your key) using ssh-copy-id will allow you to transfer your public key (not private) to the H2. In general it is best to limit the number of machines on which your private key is installed. Try to keep it to a few secure machines only to prevent its loss. –  Alex Sep 6 '11 at 15:21
    
How do I copy my private key to H2? –  Bruce Sep 6 '11 at 15:25
add comment

Your Answer

 
discard

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.