Skip to content

Instantly share code, notes, and snippets.

@Pamblam
Last active April 13, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pamblam/981324205bebd2ecba91c05acc6e6239 to your computer and use it in GitHub Desktop.
Save Pamblam/981324205bebd2ecba91c05acc6e6239 to your computer and use it in GitHub Desktop.
A condensed version of these pages, for quick reference: https://help.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

Switching a repo from http to ssh

Check for existing keys

ls -al ~/.ssh

Generate new key (substitute email)

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

Add ssh key to aget

On Mac:

Ensure this file: ~/.ssh/config, contains the following:

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

and then run

ssh-add -K ~/.ssh/id_rsa

On Linux:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

Add SSH Key to Github account

Print and copy the contents of the ssh key to the clipboard:

cat ~/.ssh/id_rsa.pub

Log into Github and go to the keys page in settings (https://github.com/settings/keys) and create a new key with a descriptive title and paste the contents of the key.

Switch the remote URL of the repo (substitute repo)

Check the remote URL of the repo with git remote -v. Copy the SSH url from the github repo's Clone button. Go to the repo directory and run:

git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment