17

This is the problem: I use Git Shell installed with GitHub for Windows. I have 3 ssh keys inside C:\Users\MyName\.ssh:

  • github_rsa (this is the key generated by github for windows)
  • id_rsa (generated by me)
  • tm_rsa (generated by me)

I inserted the key with this command:

ssh-add ~/.ssh/github_rsa
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/tm_rsa

Everytime I reboot the computer, ssh keeps forgetting the keys. if i do this command ssh-add -L, it shows only one key, usually github_rsa.

How can I avoid having to enter the keys each time?

retrobitguy
  • 535
  • 1
  • 6
  • 18

4 Answers4

7

I think you have to add it to your git bash shell, in .bashrc

eval `ssh-agent`
ssh-add
Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
  • actually, there is a post that says this: http://stackoverflow.com/questions/5727555/remember-password-git-bash-under-windows – Stuart Siegler Apr 18 '15 at 12:01
  • 1
    I have created `~/.bashrc` and added those two lines, but nothing is changed. If i restart the pc the problem persist. Do I need to do something more? *edit* If I try those commands from Git Shell, the command eval is not recognised. – retrobitguy Apr 18 '15 at 15:12
  • 1
    From the options of GitHub for Windows I have changed the default shell from "PowerShell" to "Git Bash". Now when I run the Git Bash it ask for the passphrase of id_rsa, but not for the other two keys. And if I close and re-open the Git Bash, it still doesn't remember the keys. – retrobitguy Apr 18 '15 at 16:27
  • I have the same problem. Don't even need to restart windows the bash shell will do. – Craig.C Jul 21 '19 at 18:46
0

Try

$ ssh-add -L
The agent has no identities.

If you see this message, just run ssh-add.

Here's the source: https://stackoverflow.com/a/39616339/2941404

Rajjeet
  • 29
  • 3
0

First add your private key via ssh-add:

ssh-add /path-to-private-key 

then enter the passphrase.

and then run: ssh-add

if You've already lost connection, I mean ssh-add has no identities, and then you run ssh-add, it will not work. To make it work you have to do all the process in one session.

To automate that just add this line to your .bashrc file:

ssh-add -L || ssh-add /path-to-private-key;ssh-add;
0
eval `ssh-agent`

this one works per session. It kills the ssh-agent after leaving the ssh session, for example from vscode.

The following one runs the ssh-agent in the background and won't kill the agent after leaving the ssh session.

eval "$(ssh-agent -s)"

Then just simply add your generated key

ssh-add ~/.ssh/<keyfile>
Ferooz
  • 31
  • 1