Monday, January 25, 2010

best ssh code snippet

This code snippet ssh's into the account you want to add your public key to.

The usual way to do that is to copy the key over then follow the key to the server and append it to the end.

e.g.

scp ~/.ssh/id_dsa.pub user@host:.
ssh user@host 'cat id_dsa.pub >> ~/.ssh/authorized_keys'

You can do it all in one line.

ssh user@host 'mkdir ~/.ssh;echo '`cat ~/.ssh/id_dsa.pub`' >> ~/.ssh/authorized_keys'

Be careful with the >> if you accidently do a single >, then bye bye original file. You will be able to log in but everyone else who had their key in it cant as your key is now only in that file.

this snippet came from http://snippets.dzone.com/posts/show/2335