Skip to content

Instantly share code, notes, and snippets.

@amercier
Last active August 29, 2015 14:00
Show Gist options
  • Save amercier/68c00638299adb362220 to your computer and use it in GitHub Desktop.
Save amercier/68c00638299adb362220 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
if [ "$1" == "" ]; then
echo "Syntax: $0 HOST" >&2
exit 1
fi
if [ ! -e ~/.ssh/id_rsa.pub ]; then
echo "Generating private/public keys..."
ssh-keygen -t rsa || exit 1
else
echo "Found public key ~/.ssh/id_rsa.pub, no need to generate it"
fi
echo "Sharing public key with $1..."
ssh "$1" mkdir -p .ssh \
&& cat ~/.ssh/id_rsa.pub | ssh "$1" 'cat >> .ssh/authorized_keys'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment