Add SSH to Github

Table of Contents

Generate a new SSH key pair

  1. Open a terminal window.
  2. Generate a new SSH key pair by running the following command:
ssh-keygen -t rsa

This will create two files:

* `id_rsa`: This is your private key. Keep it safe!
* `id_rsa.pub`: This is your public key. You can share this with others.
  1. Copy the contents of your public key to the clipboard by running the following command:
cat ~/.ssh/id_rsa.pub

or automatically copy to clipboard

pbcopy < ~/.ssh/id_rsa.pub
  1. Go to your GitHub account settings.
  2. Click on SSH and GPG keys.
  3. Click on New SSH key.
  4. Paste your public key into the Key field.
  5. Click Add SSH key.
  6. You're done! You can now clone your repositories using the SSH URL.

If you wanna change current remote url to ssh url

  1. Remove current remote url
git remote rm origin
  1. Add new remote url
git remote add origin your_new_remote_url

If you use ssh key with passphrase, you can use ssh-agent to save your passphrase

  1. Start the ssh-agent in the background.
eval "$(ssh-agent -s)"
  1. Add your SSH private key to the ssh-agent.
ssh-add ~/.ssh/id_rsa
  1. Now you can push your code without typing your passphrase every time.