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

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

To get my public key onto a server I normal copy the contents of my public key, then SSH into the server, then I run vi .ssh/authorized_keys, then paste my key into the file and save.

There has got to be an easier, one step way using SCP or something like that. Of course I want to append my key to authorized_keys, not overwrite it and the permissions of authorized_keys needs to remain at 600

share|improve this question
up vote 9 down vote accepted

You can also try this one liner:

cat ~/.ssh/ | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
share|improve this answer
This is perfect. Unfortunately the ssh-copy-id is not included in Mac OS X, so this one liner script will have to do and it works great. Thanks. – Shane Stillwell Aug 16 '10 at 14:14
@ShaneStillwell - try brew install ssh-copy-id – Yehosef Aug 31 '15 at 7:06

I would suggest looking into the ssh-copy-id tool, ssh-copy-id -i .ssh/id_rsa

more on and

share|improve this answer

ssh-copy-id is a script that will do exactly what you want:

share|improve this answer
I feel like an idiot, not knowing this command was available on linux machines, but it's not available by default on a Mac. Thanks for the answer thought. – Shane Stillwell Aug 16 '10 at 14:15

you could also get copymyid from here. Its a command line application designed to be a replacement for ssh-copy-id on osx. The app appends the specified pub file to your server.

share|improve this answer

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.