Skip to content

Instantly share code, notes, and snippets.

@hectormatos2011
Forked from treelzebub/setup-github-key.sh
Last active August 2, 2017 01:07
Show Gist options
  • Save hectormatos2011/e8eb6f961311dfde8fb457e9d0b1c93e to your computer and use it in GitHub Desktop.
Save hectormatos2011/e8eb6f961311dfde8fb457e9d0b1c93e to your computer and use it in GitHub Desktop.
Generate new public key (or use existing) and copy to clipboard, to paste into GitHub
#!/bin/bash
# This is a simple script that sets up a public SSH key and copies it to the
# clipboard, so you can paste it into your GitHub account here:
# https://github.com/settings/keys
#
# It only handles the default public key name, id_rsa. Deal with it :D
# Check for existing public key
keys=`find ~/.ssh -type f -name 'id_rsa.pub'`
if [[ $keys == "" ]]; then
ver=`sw_vers -productVersion`
echo """
You're running macOS version $ver. If that's greater than 10.2,
you'll need to add this to ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
"""
# Public key does not exist. Create one.
# Query for email address associated with github account
echo "Please provide the email address associated with your GitHub account: "
read email
echo
echo "Generating new SSH keys. Please accept the default name, id_rsa, if you want this to work."
ssh-keygen -t rsa -b 4096 -C $email
# Add it to the chain
ssh-add -K ~/.ssh/id_rsa
fi
pbcopy < ~/.ssh/id_rsa.pub
echo "Public key copied to clipboard!"
# Direct to github
python -mwebbrowser https://github.com/settings/keys
# Party off.
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment