Sun Aug 16 2020

How to Generate an SSH for GitHub

SSH also known as Secure Shell or Secure Socket Shell and usually considered more secure, for basic usage of GitHub

Author: Cesar Gomez

GitHubmacOS

Create an SSH key

you should be located in home (but is not required) and from there open your terminal and use the following command:

  ssh-keygen -t rsa -b 4096 -C "your_email_here"

  #or if you want an ed_25519, do:
  ssh-keygen -t ed25519 -C "your_email_here"

let’s explain each flag:

your email should be wrapped into quotes

Check the SSH agent

Check if the SSH agent is running, and if is running you will receive a pid (Process id) back

  eval "$(ssh-agent -s)"
  # Agent pid 2794

Create config file

To create the config file we need to access to the ~/.ssh folder that should be located in your home directory.

  cd ~/.shh

Once you access to the folder we can create the config file with VIM, VSCode or any other you prefer:

  #with vim
  vim config

  #with vscode
  code config

Once the config file is create, add this lines into it, then you config file is ready.

  Host *
    AddKeyToAgent yes
    UserKeychain yes
    IdentifyFile ~/.ssh/id_rsa

Add the SSH key

To add the key simple type this in you command line:

  ssh-add -K ~/.ssh/id_rsa

Add the public key into GitHub

First you need to copy the public key from the ~/.ssh folder, to do that, execute the following command:

  cat id_rsa.pub
  # if you are using ed25519, do
  cat id_ed25519.pub

now you can copy the public key and login into your GitHub account and go to:

then you can go into the repository you want to clone and switch from HTP to SSH.

Change the url from an existing repository:

If you cannot do push, pull or any other from your local repository, you might be consider replace the URL

  git remote -v
  # to list all the origins with details
  git remote set-url origin <URL>
  # change the origin URL, replace <URL> for the URL without the <>