Wednesday, January 9, 2008

Transporting and putting ssh public keys on remote servers the easy way

I login to a lot of Linux boxes, and I use ssh public keys to login. When I create a new account/server, I have to:

  1. copy over my ssh public key to the remote host
  2. login to the remote host
  3. put the public key in the authorized_keys file, set the permissions etc.
  4. delete the copy of the public key

I figured there ought to be an easier way to do this, and here it is:
cat .ssh/id_rsa.pub | ssh parijat@192.168.1.97 "mkdir -p ~/.ssh ; cat - >> ~/.ssh/authorized_keys ; chmod -R go-rwx ~/.ssh"

No comments: