Skip to content

Instantly share code, notes, and snippets.

@roderik
Created June 21, 2010 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roderik/446808 to your computer and use it in GitHub Desktop.
Save roderik/446808 to your computer and use it in GitHub Desktop.
#!/bin/bash
rhost=$1
shift
port=$1
if [ "$port" == "" ]; then
pstring="ssh $rhost"
else
pstring="ssh $rhost -p $port"
fi
if [ ! -d ~/.ssh ]; then
mkdir ~/.ssh
fi
if [ -f ~/.ssh/id_dsa.pub ]; then
echo "putting ~/.ssh/id_dsa.pub"
cat "$HOME/.ssh/id_dsa.pub" | $pstring 'if [ ! -d ~/.ssh ]; then echo creating remote dot ssh; mkdir ~/.ssh; else echo remote dot ssh dir exists; fi ;cat >> ~/.ssh/authorized_keys; chmod -R og-rwx ~/.ssh'
else
if [ -f ~/.ssh/id_rsa.pub ]; then
echo "putting ~/.ssh/id_rsa.pub"
cat "$HOME/.ssh/id_rsa.pub" | $pstring 'if [ ! -d ~/.ssh ]; then echo creating remote dot ssh; mkdir ~/.ssh; else echo remote dot ssh dir exists; fi ;cat >> ~/.ssh/authorized_keys; chmod -R og-rwx ~/.ssh'
else
echo "please save your ssh key in ~/.ssh/id_dsa.pub"
ssh-keygen -d
echo "putting ~/.ssh/id_dsa.pub"
cat "$HOME/.ssh/id_dsa.pub" | $pstring 'if [ ! -d ~/.ssh ]; then echo creating remote dot ssh; mkdir ~/.ssh; else echo remote dot ssh dir exists; fi ;cat >> ~/.ssh/authorized_keys; chmod -R og-rwx ~/.ssh'
fi
fi
$pstring 'cat ~/.ssh/authorized_keys | uniq > ~/.ssh/akn; mv ~/.ssh/akn ~/.ssh/authorized_keys; chmod -R og-rwx ~/.ssh'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment