[Git]: Authenticate GitHub Account with SSH Key (macOS, Linux)

git

mac

03/21/2020


Create new ssh key

BASH
ssh-keygen -t rsa -b 4096 -C "[email protected]"

If you're in an environment that uses sudo for most commands, be sure to include sudo

Put email inside "". Press enter for prompts

Copy SSH key

BASH
pbcopy < ~/.ssh/id_rsa.pub

Copies generated ssh key to the clipboard

If pbcopy is not applicable, run cat ~/.ssh/id_rsa.pub and copy the text

Save copied key on GitHub

Go to SSH and GPG keys on your profile —> Settings —> SSH and GPG keys

1 2

Click New SSH Key 3

Type in any title for your SSH key and paste copied ssh key in then Add SSH key 4

Created SSH key looks like this 5

Add key to ssh-agent

Run ssh-agent

BASH{OUTPUTLINES:
eval "$(ssh-agent -s)"
Agent pid 5190

(macOS only): modify ~/.ssh/config

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

Add SSH private key to ssh-agent

BASH
ssh-add ~/.ssh/id_rsa # Add -K option for macOS users

Test SSH Connection

BASH{OUTPUTLINES:
Hi EllisMin! You've successfully authenticated, but GitHub does not
provide shell access.

Type yes to the prompt

Make sure to use SSH URL when you're authenticated via SSH key. This applies to commands such as git clone, git fetch, git pull, or git push to a repository

6 7


WRITTEN BY

Keeping a record