SSH Keygen - biswajitsundara/gitdoc GitHub Wiki

SSH keys are a pair of public and private keys are used to authenticate/establish connection between client and remote machines.

  • We need to generate the keys and keep the private key in our computer/laptop
  • And add the public key in the github.
  • So whenever our computer/laptop will try to connect to github cloud, it will allow.

1. Generate the SSH Key

$ ssh-keygen -t rsa -b 4096 -c "[email protected]"

t -- specifies the type of key to be created. The commonly used is "rsa"
     There is another type also "dsa"
b -- specifies the number of bits in the key. In general 2048 is sufficient
     we can use 4096
c -- specifies the comment. The comment I have used my email id.

When we execute the command it will ask for the pass phrase.
The pass phrase is nothing but the password.
Just hit enter to skip setting the password, else set the password.

2. Start the SSH agent

$ eval $(ssh-agent -s)

  • ssh-agent is a key manager for SSH.
  • It holds your keys and certificates in memory unencrypted, and ready for use by ssh .
  • It saves you from typing a passphrase every time you connect to a server.

3. Add the private key

$ ssh-add ~/.ssh/id_rsa

  • The ssh-add command takes the private key password
  • And adds it to the list maintained by ssh-agent

4. Copy the public key

$ clip < ~/.ssh/id_rsa.pub

This will copy the public key to the clipboard

5. Add the public key in Git

  • Go to your remote git repo https://github.com/username
  • Profile -> Settings -> SSH & GPG Keys
  • Click on 'New SSH Key
  • Title = the title of the key (e.g home_dell)
  • Key = Paste the key copied to clipboard

The complete Flow

biswa@DESKTOP-8DO45Q1 MINGW64 ~
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/biswa/.ssh/id_rsa):
Created directory '/c/Users/biswa/.ssh'.

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Your identification has been saved in /c/Users/biswa/.ssh/id_rsa
Your public key has been saved in /c/Users/biswa/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:ILdWXE6NkeRdfgdfgdf645nghjghWb2Z4PD5Is [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|   oAo.o=CO     |
|  .=+.+o+OO..    |
|    +.+o+=oo     |
|     +=+= .      |
|     +o=$.       |
|       . = .     |
|      E .        |
|                 |
+----[SHA256]-----+

biswa@DESKTOP-8DO45Q1 MINGW64 ~
$ eval $(ssh-agent -s)
Agent pid 926

biswa@DESKTOP-8DO45Q1 MINGW64 ~
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /c/Users/biswa/.ssh/id_rsa:
Identity added: /c/Users/biswa/.ssh/id_rsa ([email protected])

biswa@DESKTOP-8DO45Q1 MINGW64 ~
$ clip < ~/.ssh/id_rsa.pub
⚠️ **GitHub.com Fallback** ⚠️