Logging in with an SSH key doesn't work on Git Bash but does in Windows Command Prompt

10,461

You can load the key by running ssh-add path-to-private-key

ssh-add /Users/ben/id_rsa

The predefined path is UserHome -> .ssh -> private-key & public-key

/c/Users/USERNAME/.ssh/id_rsa
/c/Users/USERNAME/.ssh/id_rsa.pub

There are restrictions to the name of the file as well as the location. Following are the known filenames that SSH agent will look for that I can think on top of my head:

  • identity
  • id_dsa
  • id_rsa

These names are generally determined by the Type you've used to generate them. Most commonly used is rsa which creates id_rsa and id_rsa.pub.

Also, most Windows user uses Putty as the SSH daemon. It works pretty well. The best thing about that is it has GUI to set the specific private key so it loads that every time without having to do any of the above stuff.

Share:
10,461
Ben Gubler
Author by

Ben Gubler

I'm a teenager who enjoys computer programming. By day, I'm (during the summer) a lawnmower and (during the school year) a student. By morning, afternoon, and night, I'm a coder, mountain-biker, reader, entrepreneur, and tinkerer-with-cool-stuff. Currently, one of my main projects is Squirrelly, a new and fast template engine written in JS.

Updated on June 04, 2022

Comments

  • Ben Gubler
    Ben Gubler almost 2 years

    I'm following this tutorial to set up my first DigitalOcean droplet, and I just generated a Key Pair for Public Key Authentication. After using ssh-copy-id (from Git Bash, since the command isn't available in Command Prompt) to add the key to my Droplet, I can SSH into my droplet just fine from Command Prompt.

    However, when I try to SSH from Git Bash, it still prompts me for my password! I've checked, and the SSH keys exist on my Droplet and on my computer. What's the problem?

    • Praveen Premaratne
      Praveen Premaratne over 5 years
      I don't believe Git Bash load private key automatically unless you put it on the predefined path by SSH. Have you tried adding your key to the agent manually?
    • Ben Gubler
      Ben Gubler over 5 years
      @PraveenP No, how would I do that? What's the predefined path?
  • Ben Gubler
    Ben Gubler over 5 years
    Whenever I run ssh-add in Git Bash, it prints this message: Could not open a connection to your authentication agent..
  • Praveen Premaratne
    Praveen Premaratne over 5 years
    Oh, that's because you have no "active agent" you need to run eval `ssh-agent` first which will print something like this Agent pid 21561. Then you can run the rest of the commands. If that doesn't work try this instead eval $(ssh-agent). That is the Linux one, one above is Unix (MacOSX)