Skip to content

Instantly share code, notes, and snippets.

@webhat
Last active August 29, 2015 13:57
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 webhat/9546473 to your computer and use it in GitHub Desktop.
Save webhat/9546473 to your computer and use it in GitHub Desktop.
Add your ssh key to a new remote version
#!/bin/sh
KEY="$HOME/.ssh/id_rsa.pub"
U=$2
echo $U
if [ -z "$U" ] ;then
U=deploy
fi
if [ ! -f $KEY ];then
echo "private key not found at $KEY"
echo "* please create it with "ssh-keygen -t rsa" *"
echo "* to login to the remote host without a password, don't give the key you create with ssh-keygen a password! *"
exit
fi
if [ -z $1 ];then
echo "Please specify user@host.tld as the first switch to this script"
exit
fi
echo "Putting your key on $1 for user $U... "
KEYCODE=`cat $KEY`
ssh -q $1 "useradd -m $U ; mkdir ~$U/.ssh 2>/dev/null; chmod 700 ~$U/.ssh; echo "$KEYCODE" >> ~$U/.ssh/authorized_keys; chmod 644 ~$U/.ssh/authorized_keys ; chown -R $U ~$U/.ssh"
echo "done!"
@webhat
Copy link
Author

webhat commented Mar 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment