Append SSH Key to Remote Server
I first must apologise for not blogging for ages, I have no excuse other than laziness!
I recently created a new server at home and install Ubuntu 9.10 Server on it. As a consequence all the SSH keys I used to access my old server were lost and I needed to add them back again….one at a time from each machine I use to access it.
Although this does not seem a big deal, the method I was using previously was as follows:-
cat ~/.ssh/id_rsa.pub | ssh <user>@<host> 'dd of=.ssh/authorized_keys oflag=append conv=notrunc'
Although this worked fine, I was catching up on my Linux reading and in Linux Journal #184 (August 2009) another reader Mark K. Zanfardino wrote in withe following more simplified command which works great on Ubuntu:-
ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<host>
This is not only easier to remember, it also checks that the key being added doesn’t already exist on the server! Brilliant!
If you have added the key to an ssh-agent, you can even leave out the “-i /path/to/publickey” part of the command, and it will copy all the keys that are currently added to the agent (which can be seen with ssh-add -L): ssh-copy-id @