Generate authentication key for ssh

authenticationssh

(1) I use the following commands on computer A to generate authentication key for ssh from computer A to computer B

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub B:.ssh/authorized_keys2

(a) if further generate authentication key for ssh from computer A to computer C, how will you do it? is it a good way to simply use the same ~/.ssh/id_rsa.pub for A to B i.e.

scp ~/.ssh/id_rsa.pub C:.ssh/authorized_keys2

(b) if further generate authentication key for ssh from computer B to computer D, is it correct to repeat the commands for A to B on B?

ssh-keygen -t rsa
scp ~/.ssh/id_rsa.pub D:.ssh/authorized_keys2

(2) There seems to be another method for A to B:

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub B

what's the difference between (2) and (1)? What will you do if use the commands of (2) in the cases (a) and (b) of (1), especially (b)?

Thanks and regards!

Best Answer

I use method 1 and copy my public key to all the servers I want access to (using that key). The public key provides no way of identifying the other places it might be distributed to, and if you start using multiple keys for multiple hosts you are trying to access, you are just going to create a management nightmare for yourself.

Just make sure you keep your private key private and secured with a passphrase.

Related Question