Tutorial — Connect Your Computer to GitHub Account Using SSH Keys

By generating SSH keys of your computer and connect it to the corresponding GitHub account, you are good to start making your contributions on GitHub community!

I-No Liao
I-No Liao
Sep 1, 2018 · 2 min read

Published at 2018/09/01

The tutorial is more like a memo for myself to set connection between my computer to GitHub account. Hope the contents help you as well :)


1. Email Settings on GitHub

On GitHub.com, go Settings → Emails → Set your email account on GitHub

2. Generate SSH Keys of Your Computer

Follow the official guide here, or the steps below.

Check existing SSH keys if any on root directory by:

$ ls -al ~/.ssh

Generate a new SSH key by

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

If prompted “Enter a file in which to save the key”, press Enter to use default location to save keys. Then, you should be asked to set a passphrase. Enter the your personal passphrase and remember it to get access in the future.

To add SSH key to the ssh-agent, start ssh-agent in the background by

$ eval "$(ssh-agent -s)"

Create or modify “~/.ssh/config” configuration file to automatically load keys into the ssh-agent and store passphrase in the keychain.

$ vim ~/.ssh/config

In the config file, insert the following and save the file.

Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

Finally, add SSH key to the ssh-agent by

$ ssh-add -K ~/.ssh/id_rsa

At this point, you have successfully generated the computer’s SSH key and the next step is to connect the key to GitHub. Copy the key to the clipboard by

$ pbcopy < ~/.ssh/id_rsa.pub

On GitHub.com, go Settings → SSH and GPG keys → New SSH key → Type title in the “Title” field → Command-V (or Ctrl-V)to paste SSH key in the “Key” field → Add SSH key.

Then, test your SSH connection to GitHub by

$ ssh -T git@github.com

You may receive a warning, enter “yes”. Afterwards, the terminal should prompt

Hi username! You've successfully authenticated, but GitHub does not
provide shell access.

3. Set Your Commit Email Address in Git

The Q&A is here. To successfully make git commits link to your account, follow the official guide here, or the steps below.

Set email address in Git by

$ git config --global user.email "email@example.com"

To confirm the email setting, enter

$ git config --global user.email

The email you just entered should prompt on the terminal.

4. You are all set!

Close the terminal and re-open. Try to commit and push. Your commit should link to your account correctly now.


Summary

The official guide provided by GitHub.com is clear except for linking git commits to the right user account. Step 3 covers this part.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade