What, exactly, does ssh-copy-id do?

DanHeidel picture DanHeidel · Mar 27, 2014 · Viewed 12.1k times · Source

What does the ssh-copy-id command do, exactly? I've used it numerous times and it works great. However, when I try to manually cut and paste my .pub keyfile to my remote authorized_keys, it doesn't work.

I've compared the contents of my authorized_keys file where I've cut and pasted the .pub into it vs subsequently using ssh-copy-id and I'm not seeing any differences between the two, including whitespace.

Is there anything that ssh-copy-id does beyond copying the public key into authorized_keys?

Answer

ganqqwerty picture ganqqwerty · Dec 2, 2014

This little command really should work. I use it every time there is no ssh-copy-id, for example when I'm on Mac.

cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'cat >> ~/.ssh/authorized_keys'

IMO It's better than manual copy and paste: in this case you know exactly what content will end up in the file