6

if we want to add our private ssh key we have to write in e.g powershell

ssh-add ~\.ssh\id_rsa

but is there possibility to check, what key is currently added to agent ?

I can't find that command on the internet.

discCard
  • 421
  • 1
  • 5
  • 16
  • 1
    this is about linux, on windows it doesn't work – discCard Dec 09 '20 at 14:17
  • ok, granted :) Does `ssh-add -l` or `ssh-add -L` output something ? or are these options not recognized at all by your version of `ssh-add` ? – LeGEC Dec 09 '20 at 15:46
  • 2
    Check how you can start your agent, and set the expected variables in your shell. Still a Unix question : https://unix.stackexchange.com/q/464574/33732, but the `eval $(ssh-agent)` can probably be adapted for pwsh – LeGEC Dec 10 '20 at 00:13
  • If you are afraid of adding the same key more than once, you don't need to worry, even executing the same command several times will always have the same key once, as if it were always overwriting the previous key. You can confirm with `ssh-add -L` Works fine on Windows. – MMJ Dec 28 '22 at 17:51

1 Answers1

10

GitHub has a documentation for Windows explaining how to launch the ssh-agent automatically from a git bash session (with the .bashrc)

Once launched, a ssh-add -L will list the active keys.

From there, ssh-add -l/-L will list the register keys fingerprint, pr keys content.
(And ssh-add is included in Git for Windows)

You can compare a fingerprint from ssh-add -l with ssh-keygen -lf /path/to/ssh/key in order to determine which key filename was added to the agent.
(and ssh-keygen is also included with Git for Windows)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • the problem with this github doc is: it works only for single instance terminal/cmd/bash, if you will open next one terminal, your password is not remember – discCard Dec 11 '20 at 11:45
  • @discCard True, because the ssh-agent will have to relaunch from that new session. That is why I use HTTPS URLs, with cached credentials stored in a common store (common to all sessions) – VonC Dec 11 '20 at 11:47
  • 1
    FYI - I was able to get it so the passphrase is only prompted for on the first window that's opened after booting using the script at [Auto-launching ssh-agent on Git for Windows](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/working-with-sshkey-passphrases#auto-launching-ssh-agent-on-git-for-windows). I did find, however, it didn't work when I added it add it to either `~/.profile` or `~/.bashrc`. I needed to add it to `~/.bash_profile` for it to get picked up and used by Git Bash on Windows. – csrowell Feb 10 '22 at 15:10
  • @csrowell Thank you for this feedback. I remember that file now: https://stackoverflow.com/a/32353083/6309 – VonC Feb 10 '22 at 15:16
  • @VonC, thank you for the link - the inconsistency was bugging me - mystery solved. – csrowell Feb 10 '22 at 15:21