Auto SSH Key

This small script (basically a one-liner) will transfer your public ssh key (if in standard ~/.ssh/id_dsa.pb) and properly set permissions to the host passed as the first argument. This makes it so the only time you need your password (if using a passphrase-less ssh-key) will be when running this script. After that, you will have your ssh key access done automatically!

Example:
user@host1 ~ $ sshme user@some.domain.com
user@some.domain.com’s password:
user@host1 ~ $ ssh user@some.domain.com
Last login: Tue Oct 30 22:47:42 2007 from ipXX.XXX.XXX.XXX
user@some.domain.com ~$

The sshme script:

#!/bin/bash

cat ~/.ssh/id_dsa.pub | ssh $1 \
"mkdir -p ~/.ssh; \
 cat - >> ~/.ssh/authorized_keys; \
 chmod u+rwx ~ ~/.ssh; \
 chmod go-rw ~ ~/.ssh; \
 chmod 600 ~/.ssh/authorized_keys"


Bookmark and Share