Colonize.sh

From Stack Overflow
Jump to: navigation, search

colonize.sh Pushes your ssh public key to a server for passwordless authentication

#!/bin/bash
if [ -z "$1" ]; then
	echo "colonize.sh by Brian Enigma <brian@netninja.com>"
	echo "Function: copies ssh public keys to remote machines for passwordless login"
	echo "Usage: colonize.sh <username>@<servername or ip address>"
	exit 1
fi
KEY=id_rsa.pub
STORE=authorized_keys
CONTENT=`cat ~/.ssh/$KEY`
echo "Attaching key to authorized_keys file"
ssh $1 "mkdir -p .ssh && chmod 700 .ssh && touch .ssh/$STORE \
	&& chmod 644 .ssh/$STORE \
	&& echo '$CONTENT' >> .ssh/$STORE"
echo "Complete!  You should be able to log in without a password now!"
Personal tools