Skip to content

Instantly share code, notes, and snippets.

@troyxmccall
Created January 26, 2016 04:46
Show Gist options
  • Save troyxmccall/bd7e93fa63565edf0cbb to your computer and use it in GitHub Desktop.
Save troyxmccall/bd7e93fa63565edf0cbb to your computer and use it in GitHub Desktop.
function keyme () {
if [ -z "$1" -o -z "$2" ]; then
echo "Please provide your email and a name for the key (preferably the server domain) - usage: newkey <email> <keyname>"
return 1
fi
ssh-keygen -t rsa -b 4096 -C "$1" -f "$HOME/.ssh/${2}_rsa"
read -r -p "Would you like to upload this key to a server now? [y/N] " response
response=${response} # tolower
if [[ $response =~ ^(yes|y)$ ]]; then
echo -n "Enter the server hostname or IP address and press [ENTER]: "
read server
echo -n "Enter your username for $server and press [ENTER]: "
read username
ssh-copy-id -i "$HOME/.ssh/${2}_rsa.pub" "$username@$server"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment