Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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/ B:.ssh/authorized_keys2

If further I need to generate authentication keys for ssh from Computer C to Computer B, how to prevent overwriting the existing file .ssh/authorized_keys2 on B for A to B?

Thanks and regards!

share|improve this question

2 Answers 2

Upload it under a different name, e.g. .ssh/newkey, then ssh in and

cat .ssh/newkey >> .ssh/authorized_keys2

Or if you would like to be tricky and do it all in one step,

ssh user@host "cat - >> .ssh/authorized_keys2" <
share|improve this answer
A#ssh-copy-id B
C#ssh-copy-id B

You can pass -i .ssh/ to ssh-copy-id if you need to copy a specific pub key. authorized_keys can have multiple key entries, you are not limited to one.

If you do ssh hoping (ssh to a, then from a to b, and from b to c) it might interest you the -A argument to ssh (forwarding keys trough ssh-agent).

share|improve this answer
ssh-copy-id is just a shell script, so it makes a good reference as well. If you have if, you can use type -t ssh-copy-id (or maybe which) to see where it is, the look at it with cat/less/vim. – Kyle Brandt Oct 27 '09 at 11:53

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.