Error connecting to agent: no such file or directory - adding key to ssh agent [closed]
Asked Answered
C

8

54

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
Carpetbagger answered 15/1, 2021 at 18:38 Comment(1)
You need to manually start ssh-agent service first look hereModica
P
51
  • Start Windows PowerShell with Run as Administrator mode.
  • Follow these commands there...
Get-Service ssh-agent | Set-Service -StartupType Automatic

# By default the ssh-agent service is disabled. Configure it to start automatically.
# Make sure you're running as an Administrator.
Start-Service ssh-agent

# Start the service
Get-Service ssh-agent

# This should return a status of Running
ssh-add <complete-key-path-here>

Key Path Example: C:\Users\so\.ssh/key-name
# Now load your key files into ssh-agent

Original Source: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_keymanagement

Papist answered 21/12, 2022 at 17:54 Comment(0)
G
23

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

Getter answered 24/1, 2022 at 9:32 Comment(1)
This fix did it for me! Thanks!!Assignee
R
21

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.

Rife answered 22/4, 2021 at 15:56 Comment(0)
R
16

Try to type:

ssh-agent bash

and then execute:

ssh-add...
Rubeola answered 1/12, 2021 at 15:54 Comment(1)
for zsh it's ssh-agent zshSeptima
G
13

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.

Grouping answered 16/1, 2021 at 12:26 Comment(0)
M
3

In my case, the ~ was the problem. Once I typed out my full path ssh-add C:\Users\qa95\.ssh\id_rsa it worked.

Looks like the tilde expansion to the user's directory is not fully supported in PowerShell, so even though dir ~\.ssh\id_rsa may work fine, ssh-add doesn't like it.

Monstrance answered 22/6, 2022 at 18:12 Comment(0)
C
3

This was also happening to me on Windows. I was able to fix this way:

  1. For Windows, leave a blank passphrase when creating the ssh file
  2. Make sure your HOMEPATH env is pointing to where the .ssh folder is saved
$env:HOMEPATH='C:\Users\<username>'
Comp answered 25/10, 2022 at 18:30 Comment(0)
F
-3

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

Footplate answered 1/11, 2021 at 23:57 Comment(2)
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.pubMcclish
I have updated answer with your infromationFootplate

© 2022 - 2024 — McMap. All rights reserved.