19

I am trying to add key that I have generated to the ssh agent. Below are my steps

C:\repo>ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\mante1/.ssh/id_rsa):C:\repo\key

After the key is generated, I am starting the ssh agent and adding it

C:\repo>start-ssh-agent
Found ssh-agent at 13460
Found ssh-agent socket at /tmp/ssh-vKzdrs37QYVK/agent.821

C:\repo>ssh-add ~/.ssh/id_rsa
Error connecting to agent: No such file or directory
qa95
  • 199
  • 1
  • 1
  • 3
  • You need to manually start ssh-agent service first [look here](https://stackoverflow.com/questions/52113738/starting-ssh-agent-on-windows-10-fails-unable-to-start-ssh-agent-service-erro) – Shashwat Pathak Apr 29 '22 at 15:33

5 Answers5

10

VonC is probably right, in that you need to fix your path, but I was facing the same problem despite using the correct one. In my case, I needed to start ssh-agent for the command to work.

Running the sample commands from GitHub was not working, but, since I had installed OpenSSH, I simply started the pre-installed "OpenSSH Authentication Agent" service, on the Services app, as described in this answer.

ravemir
  • 1,003
  • 2
  • 13
  • 28
6

If you have generated your key at C:\repo\key, then the key you need to ssh-add is... C:\repo\key, not ~/.ssh/id_rsa

C:\repo>ssh-add C:\repo\key

That would work.

VonC
  • 1,129,465
  • 480
  • 4,036
  • 4,755
6

This problem is maybe because you have two types of ssh-agent.exe , you can see them in task-manager , one ssh-agent will be from git and other one would be from OpenSSH.

Fix

  1. End all ssh task from task-manager
  2. Go to the directory where the key is in your case C:\repo\key this should be your working directory and then run start-ssh-agent will automatically add your private key to the ssh and you won't need the ssh-add command .

Imp

  1. start-ssh-agent will use the ssh from git
  2. start ssh-agent will use the ssh from OpenSSH

So there can be inconsistencies between the version of ssh you're using and your keys are added/generated with

Prashant Joshi
  • 137
  • 3
  • 6
3

Try to type:

ssh-agent bash

and then execute:

ssh-add...
-3

It's also important to have it exactly in specific user directory in a folder name '.ssh' and file names have to be id_rsa and id_rsa.pub

Faris Kapo
  • 340
  • 8
  • 28
  • They actually do not have to be id_rsa and id_rsa.pub. For instance I have a corporate ssh key with that name, but my personal keys are named id_rsa_personal and id_rsa_personal.pub – Onat Korucu May 21 '22 at 10:20