Skip to content

Instantly share code, notes, and snippets.

@treelzebub
Last active August 21, 2022 22:39
Show Gist options
  • Save treelzebub/9deb3dcaee32439250581c1ab22e0c0c to your computer and use it in GitHub Desktop.
Save treelzebub/9deb3dcaee32439250581c1ab22e0c0c to your computer and use it in GitHub Desktop.
[macOS/Debian] 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
KEY=`find ~/.ssh -type f -name 'id_rsa.pub'`
if [[ $KEY == "" ]]; then
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
## For linux, uncomment:
## xclip -sel clip ~/.ssh/id_rsa.pub
pbcopy < ~/.ssh/id_rsa.pub
echo "Public key copied to clipboard!"
# Direct to github
python3 -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