Attempting to add my SSH key to the ssh-agent but getting 'no such file or directory.'
Asked Answered
M

3

12

Below are my steps to create and attempt to add an SSH key but I'm rather unsure where I am going wrong, any help is greatly appreciated! (I'm new to this, sorry)

Following online instructions, I first generated a new shh-key using the following code:

$ ssh-keygen -t ed25519 -C "[my email]"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/c/Users/Akiper/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in
Your public key has been saved in  .pub

etc.

I then made sure that the ssh-agent was running in the background and attempted to add my generated shh-key to the shh-agent but i got the following error:

$ eval `ssh-agent -s`
Agent pid 304

$ ssh-add ~/.ssh/id_ed25519
/c/Users/Akiper/.ssh/id_ed25519: No such file to directory

As you can see in the third line of code, the key was saved in the following file:

Enter file in which to save the key (/c/Users/Akiper/.ssh/id_ed25519):

and as you can imagine, I am rather confused as to why the code says that it cannot find the key in such, or I may be interpreting the code wrong. Again, any help and advice are appreciated.

Thank you.

Mousy answered 22/1, 2021 at 20:21 Comment(5)
In cmd window: dir c:\Users\Akiper\.ssh; in git-bash: ls ~/.ssh/ — is the file there? If not, what files are there?Joliejoliet
Look at the last two lines of the output from ssh-keygen. Something fishy is going on.Mulvaney
Did you accidentally type a space before hitting Enter for the file name? It doesn't look like the default was used.Mulvaney
@Joliejoliet when I type that in, I get the following ls: cannot access `/c/Users/Akiper/.ssh/`: No such file or directoryMousy
This version of ssh-keygen appears to have a bug; it should have either created the directory /c/Users/Akiper/.ssh/ or reported an error, rather than silently doing ... whatever it is that it did.Mulvaney
J
3

Make sure you dont have any premade ssh keys in ~/.ssh/ directory then try this out ssh-keygen -t rsa -b 4096 -C "email" follow the next steps as usual ed25519 is 2048bits for rsa key whereas the above one is 4096 bits .

Judo answered 22/1, 2021 at 20:40 Comment(1)
Thank you so much! It worked! I checked if I had any premade ssh keys and it seems like something happened in my code and the key was never saved even though everything looked in order? Maybe I just interpreted it wrong. Thanks again!Mousy
E
6

Just like @iceweasel said, check if ~/.ssh/ directory is empty or not, delete any pre-existing keys. Then enter:

$ ssh-keygen -t rsa -b 2048 -C "email"

Then you will see an output such as:

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/name/.ssh/id_rsa):
                                                 leave this empty ^
Enter passphrase: 
     leave this empty ^
Enter same passphrase again:
             leave this empty ^
Your identification has been saved in /Users/name/.ssh/id_rsa 
Your public key has been saved in /Users/name/.ssh/id_rsa.pub

Afterwards, type cd ~/.ssh into the terminal and check if id_rsa and id_rsa.pub are available. Then type cat id_rsa.pub and copy the key. Add that key in GitHub's SSH key if you want: You'll find the guide here. To set up the git-agent, run eval "$(ssh-agent -s)" into the terminal. Followed by ssh-add ~/.ssh/id_rsa

After completing all these steps, you're ready to commit changes and push your work to the remote repo.

Eldridge answered 4/9, 2021 at 15:33 Comment(1)
thank you, you saved a new developer's day!Avogadro
J
3

Make sure you dont have any premade ssh keys in ~/.ssh/ directory then try this out ssh-keygen -t rsa -b 4096 -C "email" follow the next steps as usual ed25519 is 2048bits for rsa key whereas the above one is 4096 bits .

Judo answered 22/1, 2021 at 20:40 Comment(1)
Thank you so much! It worked! I checked if I had any premade ssh keys and it seems like something happened in my code and the key was never saved even though everything looked in order? Maybe I just interpreted it wrong. Thanks again!Mousy
E
0

I also had the same problem but using the full path while adding ssh-add resolves it:

ssh-add /Users/sakthi.n/.ssh/id_rsa_personal
Enumerate answered 26/8, 2024 at 9:5 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.