4

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

Shane Stillwell
  • 337
  • 1
  • 4
  • 11

4 Answers4

10

You can also try this one liner:

cat ~/.ssh/id_rsa.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
vmfarms
  • 3,077
  • 19
  • 17
  • 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 07:06
  • This may not work if .ssh directory doesn't exist, its permissions are incorrect, or if .ssh/authorize_keys permissions are incorrect. – dmourati Feb 14 '17 at 00:16
5

I would suggest looking into the ssh-copy-id tool, for example:

ssh-copy-id -i .ssh/id_rsa remoteuser@remote.host

More on:

Niklas B
  • 381
  • 1
  • 2
  • 7
2

ssh-copy-id is a script that will do exactly what you want: http://linux.die.net/man/1/ssh-copy-id

  • 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
0

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.