How to configure SSH key on windows for GitHub

Sergio Pardo
4 min readFeb 6, 2021

Quick step-by-step to create and add an SSH key on your windows computer and possible problems you may encounter down the road.

Step 0:

Open a new PowerShell window.

Step 1:

Create a new ssh key pair locally running the following command:

ssh-keygen -t rsa -b 4096 -C "example@email.com"
  • Remember to change “example@email.com” with your email

Step 2:

We need to add the private key to the local agent, so you must run:

ssh-add .\.ssh\id_rsa

Step 3:

Copy your public key into the clipboard with the following command:

cat ~/.ssh/id_rsa.pub | clip

Step 4:

Go into github and create a new SSH entry copiying the content you have on the clipboard.

Go to the dropdown on the top right corner
Go to settings
Go to the SSH and GPG keys section
Click on New SSH key
Add new SSH form

Place any title you want to identify the key, it doesn’t matter. And CTRL+V on the key pasting the content of your public key.

It should start with “ssh-rsa”, have a bunch of random numbers and letters, and end with the email you gave on the first step: “example@email.com”.

Click on “Add SSH key” and you should be all set.

Problems you may encounter and how to solve them:

  1. In some other tutorials you may have seen a command like this:
eval $(ssh-agent -s)

Do not use it on power shell, just follow all the steps on this tutorial and you should be fine.

2. When you are trying to add the key to the local agent with some “ssh-add” related command, you may encounter some error like the following:

unable to start ssh-agent service, error :1058

This means the service that runs the agent is stopped (it comes like this by default), so you should:

  • Open a new PowerShell terminal with administrator priviliges (Right-click and select “Run as administrator”).
  • Run the following command:
start-ssh-agent.cmd

(At this point you may continue the tutorial above, but I recommend you to execute the following step to avoid troubles in the future).

  • Run the following command:
Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service

(If you receive a message like: “Service ‘OpenSSH Authentication Agent (ssh-agent)’ cannot be …” it means you didn’t opened the PowerShell as administrator)

3. When creating the ssh key locally, you may receive a message that id_rsa has already been created and if do you wish to overwrite it. If you are not sure, run this command instead:

ssh-keygen -t rsa -b 4096 -C "example@email.com" -f ~.\.ssh\id_rsa_github

You can change the “id_rsa_github” for whatever you like, just make sure to adapt the tutorial to use that name on all the other commands.

4. You may also encounter some error like this:

Saving key "~.\\.ssh\\id_rsa" failed: No such file or directory

This means you are trying to perform the operation with the wrong “slash”, so use “\” instead of “/”.

--

--