GIT - generating a new ssh key and add to the account.

First time when you use git bash to clone a repository from git you will face this error,
git@github.com: Permission denied (publickey).

This is because git repository does not recognize your computer.
Now we will create ssh key so that every time you do a clone, GIT can understand who you are.
Steps - 
Git should be installed in your computer.(https://git-scm.com/downloads)

Open Git bash shell
Generate the local key

$ ssh-keygen -t rsa -b 4096 -C "bhabani.pattanayak@gmail.com"

It creates new ssh key using the email address
$ Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter]

$ Enter passphrase (empty for no passphrase): [Type a passphrase]
$ Enter same passphrase again: [Type passphrase again]

Enter a secure pass phrase you can remember.

Start the ssh agent in the background and add your private key to the agent.
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa

Copy the SSH key 
$ clip < ~/.ssh/id_rsa.pub

Then add the SSH key to your git hub account.

In the right side Account -> Setting (https://github.com/settings/profile)
Then click SSH and GPG keys. Add New SSH key.
Title - You can give any name like 'Office laptop'
Then paste the SSH key to the Key area which you copied earlier.
Now you all set.You should be able to clone git repository.

No comments:

Post a Comment