Skip to content

Instantly share code, notes, and snippets.

@LD8
Last active December 25, 2019 04:23
Show Gist options
  • Save LD8/3b2c13998d668cf80b6e6006ef0c5cee to your computer and use it in GitHub Desktop.
Save LD8/3b2c13998d668cf80b6e6006ef0c5cee to your computer and use it in GitHub Desktop.
How to set up SSH Key for GitHub

This is my first time to push a repo without using an http link so I need to generate a new SSH key. Followed the instruction on github:

Step 1 create a new ssh key, using the provided email as a label

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

# Press Enter when:
> Enter a file in which to save the key (/Users/you/.ssh/id_rsa):
# which accepts the default file location which is ~/.ssh/ folder

# Type a secure [passphrase](https://help.github.com/en/enterprise/2.17/user/authenticating-to-github/working-with-ssh-key-passphrases)
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

Step2: Add your SSH key to the ssh-agent

This is essentially a step to let mac know that you've got a key and it's at your disposal.

# start the ssh-agent
$ eval "$(ssh-agent -s)"
> Agent pid <somenumbers>

# create a config file to load keys into the ssh-agent and store passphrases in your keychain automatically
$ echo "Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa" > ~/.ssh/config
  
# Add the SSH PRIVATE key to the ssh-agent and store the passphrase in the keychain manually
$ ssh-add -K ~/.ssh/id_rsa

To be honest, I'm not quit sure why you have to add the SSH key to ssh-agent when you've already created a config file which automatically does that... Is it because the last step is to add the PRIVATE Key explicitly?

Step 3: Add the new SSH key to your Github account

This is quit straight forward. Follow the steps here on GitHub official Help.

Windows and Linux user please refer to the instruction on github..

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