Setup Git SSH Key with GitHub / GitLab

Jake Cyr
1 min readOct 1, 2020

--

It’s a pain having to enter your username and password each time you pull/push from a Git repo. Let’s learn how to setup your SSH key on you computer and connect it with GitHub to avoid having to enter your credentials.

  1. Generate a new SSH key on your computer (if you don’t have one already) with the command ssh-keygen -t rsa -b 2048 -C "email@example.com" . You can hit enter for all of the prompts unless you want to password protect your key (recommended).
  2. Now that you have your key generated, let’s view the public key with the command: cat ~/.ssh/id_rsa.pub (change the path to where you saved the key)
  3. Copy the output of the above command which will start with ‘ssh-rsa’ and end with your email.
  4. Go into your GitHub account settings (or GitLab), select ‘SSH and GPG keys’ and click ‘New SSH Key’
  5. Give your key a title (ex. Macbook) and paste the contents you copied earlier in the box below labeled ‘Key’
  6. Now your key is connected to GitHub! When cloning repos in the future make sure to copy the ‘SSH’ URL which should start with ‘git@github’…
  7. If you already have repos cloned with HTTPS and you want to change them to use your newly generated key, run the command in each repo: git remote set-url origin SSH_ORIGIN_COPIED_FROM_GITHUB

Feel free to leave comments or questions below!

If you prefer video tutorials, checkout my Git SSH key setup video below:

--

--

Jake Cyr
Jake Cyr

Written by Jake Cyr

Proficient in AI and cloud tech, advancing systems development with a commitment to continual growth.

No responses yet