[Git]: Authenticate GitHub Account with SSH Key (macOS, Linux)
git
mac
03/21/2020
Create new ssh key
If you're in an environment that uses
sudo
for most commands, be sure to includesudo
Put email inside "". Press enter for prompts
Copy SSH key
pbcopy < ~/.ssh/id_rsa.pub
Copies generated ssh key to the clipboard
If
pbcopy
is not applicable, runcat ~/.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
Click New SSH Key
Type in any title for your SSH key and paste copied ssh key in then Add SSH key
Created SSH key looks like this
Add key to ssh-agent
Run ssh-agent
eval "$(ssh-agent -s)"Agent pid 5190
(macOS only): modify ~/.ssh/config
Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa
Add SSH private key to ssh-agent
ssh-add ~/.ssh/id_rsa # Add -K option for macOS users
Test SSH Connection
ssh -T [email protected]Hi EllisMin! You've successfully authenticated, but GitHub does notprovide 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