Skip to content

Instantly share code, notes, and snippets.

@mjuneja
Created December 14, 2011 15:23
Show Gist options
  • Save mjuneja/1477004 to your computer and use it in GitHub Desktop.
Save mjuneja/1477004 to your computer and use it in GitHub Desktop.
Shell script to get my public key from a url and append to authorized_keys to grant access
#! /bin/bash
if [ ! -d $HOME/.ssh ]; then
`mkdir $HOME/.ssh`
`touch $HOME/.ssh/authorized_keys`
`chmod 0600 $HOME/.ssh/authorized_keys`
else
if [ ! -d $HOME/.ssh/authorized_keys ]; then
echo "Creating authorized_keys file"
`touch $HOME/.ssh/authorized_keys`
`chmod 0600 $HOME/.ssh/authorized_keys`
fi
fi
#get public key from a public url, mine is at dropbox
PATH_TO_KEY="http://dl.dropbox.com/u/628209/manik.pub"
echo `wget $PATH_TO_KEY`
#todo - handle failure to get key
key=`echo $PATH_TO_KEY | sed 's_.*/__' `
`cat $key >> $HOME/.ssh/authorized_keys`
`rm $key`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment