Clone GitHub project through ssh

Kishan Patel
2 min readApr 3, 2020

Simple documentation on how to clone GitHub repository into your system through ssh key.

First of all, you need to generate ssh key, check out https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent to generate ssh key.

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

Navigate to the ssh folder

$ cd ~/.ssh

Check if there is already id_rsa and id_rsa.pub file is present or not.

$ ls

Take a backup of your old ssh key, if you have

$ mv id_rsa* /Document

Remove the old keys

$ rm id_rsa id_rsa.pub

Navigate to the folder path in the terminal where you have your new ssh key

Example
$
cd /Users/admin

Copy both ssh keys and paste in .ssh folder

$ cp id_rsa* ~/.ssh/

Give access to the keys

$ sudo chmod 600 id_rsa*

Now you have completed the local setup, its time to add key in GitHub id_rsa.pub.

Let’s copy the key from id_rsa.pub file

$ cat ~/.ssh/id_rsa.pub|pbcopy

Open Github in a browser and click on the Settings option from the menu.

Then choose SSH and GPG keys from the left side menu.

After that click on the New SSH key.

Paste the copied id_rsa.pub key and give a title to that

Now you can clone your GitHub repository through ssh key. (Make sure you have git installed in your system)

Open terminal in your system navigate to the path where you want to clone

Syntax
$
git clone clone_url
Example
$ git clone git@github.com:user_name/repo_name.git

Thank you.

--

--