How to Setup SSH Keys for Git on Windows 10
2 min read
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.
- 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
ls -al ~/.ssh
This shows no
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 email@example.com
You will see the following output:
Now see the latest private/public keys in that
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
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`
Agent pid XXXX
Add rsa key to ssh:
Identity added: /c/Users/Tamal Chowdhury/.ssh/id_rsa (firstname.lastname@example.org)
Copy the public key in Windows:
clip < ~/.ssh/id_rsa.pub
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 email@example.com
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!