How to Setup SSH Keys for Git on Windows 10

In this doc, you will set up your own private and public SSH keys to securely connect to your GitHub account from your computer. This is important if you push and pull code to your GitHub profile.

Requirements:

  • You need git bash installed on your system.

Watch the video instructions from Kent C Dodds on egghead.io

Open your terminal/command prompt to check if public keys and private keys are set up under the .ssh directory:

ls -al ~/.ssh

This shows no id_rsa or id_rsa.pub setup on the system:

drwxr-xr-x 1 Tamal Chowdhury 197121    0 Mar 28 19:56 .
drwxr-xr-x 1 Tamal Chowdhury 197121    0 Mar 28 19:53 ..
-rw-r--r-- 1 Tamal Chowdhury 197121   92 Mar 28 19:53 known_hosts

Type the following to generate a new key pair:

ssh-keygen -t rsa -b 4096 -C you@youremail.com

You will see the following output:

Now see the latest private/public keys in that .ssh directory:

ls -al ~/.ssh
total 25
drwxr-xr-x 1 Tamal Chowdhury 197121    0 Mar 28 19:56 .
drwxr-xr-x 1 Tamal Chowdhury 197121    0 Mar 28 19:53 ..
-rw-r--r-- 1 Tamal Chowdhury 197121 3389 Mar 28 19:56 id_rsa
-rw-r--r-- 1 Tamal Chowdhury 197121  752 Mar 28 19:56 id_rsa.pub
-rw-r--r-- 1 Tamal Chowdhury 197121   92 Mar 28 19:53 known_hosts

Start the ssh-agent in your computer, for Mac/Linux:

eval "$(ssh-agent -s)"

Windows: Although Kent tells to type ssh-agent -s for windows, it does not start the agent. This answer tells the actual command is:

eval `ssh-agent -s`

Displays: Agent pid XXXX

Add rsa key to ssh:

ssh-add ~/.ssh/id_rsa

Output:

Identity added: /c/Users/Tamal Chowdhury/.ssh/id_rsa (you@youremail.com)

Copy the public key in Windows:

clip < ~/.ssh/id_rsa.pub

for Mac pbcodpy < ~/.ssh/id_rsa.pub

Create a new ssh key in your GitHub account:

Paste the public rsa key to Github keys, click the green "Add SSH key"

Now verify the git connection:

ssh -T git@github.com

Output:

Hi tamalchowdhury! You've successfully authenticated, but GitHub does not provide shell access.de shell access.

You have successfully authenticated with GitHub from your computer. Get coding!