Skip to content

Instantly share code, notes, and snippets.

@juanique
Last active November 2, 2024 05:49
Show Gist options
  • Select an option

  • Save juanique/4092969 to your computer and use it in GitHub Desktop.

Select an option

Save juanique/4092969 to your computer and use it in GitHub Desktop.
Bash script to add a new SSH key to your GitHub account
rm -rf ~/.ssh/id_rsa ~/.ssh/id_rsa.pub
read -p "Enter github email : " email
echo "Using email $email"
ssh-keygen -t rsa -b 4096 -C "$email"
ssh-add ~/.ssh/id_rsa
pub=`cat ~/.ssh/id_rsa.pub`
read -p "Enter github username: " githubuser
echo "Using username $githubuser"
read -s -p "Enter github password for user $githubuser: " githubpass
curl -u "$githubuser:$githubpass" -X POST -d "{\"title\":\"`hostname`\",\"key\":\"$pub\"}" https://api.github.com/user/keys
@morganrivers
Copy link

I made a little script that also does this but allows you to keep several names at once, it also contains some more explanation and walkthrough on the page. Hopefully this is useful to someone, as I found this process quite opaque when I first had to do it for my private repositories:

https://github.com/morganrivers/how_to_ssh_key

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