how to add existing key to openssh on windows?

git, openssh, putty

Solution

Some background

OpenSSH has no equivalent of pageant. Well, almost. It has an `ssh-agent.exe` program (man page) and an accompanying `ssh-add.exe` program (man page) to add keys to the agent.

The unfortunate (for Windows) thing is that the workflow assumed by `ssh-agent` is like this:

You run it, it prints some information about how it can be reached (by `ssh-add`) then detaches from the terminal and goes to the background.

The information it prints is presented in the form of a Unix shell code which sets some environment variables, so most of the time it's supposed to be run like this:

eval `ssh-agent -s`

While this sounds complicated, on any sensible Unix-like system, your Desktop Environment will make sure the SSH agent is spawned early at startup and the environment variables handed off by it are used and are inherited by all the programs later started by the user. So it just works™ without you even noticing.

You run `ssh-add` to feed keys to a running instance of `ssh-agent`.

This program locates the agent using the environment variables set on step one.

- The SSH client tries to locate the agend using the same approach as `ssh-add` when it's about to shake hands with the server.

As you can see, this model does not need to know about graphical user environments etc so you won't get any fancy tray icon and some sort of GUIs to feed your keys to the agent.

Since this obviously doesn't play well with the way a user's session is created in Windows, PuTTY implements its own approach to provide an SSH agent, its own means to locate the running agent and its own protocol to talk with it.

What you can do about this

Continue using PuTTY.

I don't use Eclipse but I know it uses JGit to work with the repository and talk with remote servers. So if you'll find a way to tell JGit how to use your own SSH client program to set up an SSH tunnel (like Git for Windows does with its `GIT_SSH` environment variable) you'll be able to use Eclipse with PuTTY.

Forfeit the security of your SSH key and work without the need for SSH agent.

For this, you might use PuTTY's `puttygen.exe` to convert the SSH key in the native PuTTY's format to the one suitable for OpenSSH without providing an encryption password—and hence obtaining an unencrypted key—and then supply that key to OpenSSH: either by placing it under `%USERPROFILE%\.ssh` and naming it `id_rsa` (yeah, `id_rsa` without any extension) or create an `%USERPROFILE%\.ssh\config` configuration file and specify there where your key is located. Refer to this manual page for its format.

Problem

I have been using putty/plink/pageant + tortoiseGIT on many computers, and found it difficult and painful and does not work with eclipse. So I decided to install tortoiseSVN and windowsGIT selecting the openssh version instead of the putty version. I have an existing key installed in github, and I have the ppk file which was generated which I would had to manually load each time I wanted to use it in pageant. But Now I am stuck. How do I do this using openssh? What is the openSSH equivalent of pageant? I suspect I have to convert the ppk into id_rsa.pub or simlar, but what do I do with them to make them usable on the local machine? Do I have to install something called openSSH in the same way I installed putty? Does it have something like pageant? Or should I give up and go back to using putty for SSH (and having to manually load keys every time) Edit 1. Haven't found anything in 2 hours of googling this. I'm going to take a wild guess that openssh is not something I need to install, but is something which came with git install. I'm going to guess that because there is no mention of it, that windows uses the same scheme as Unix, i.e. put the keys ~/.ssh/... So I used puttygen to load my ppk, then "export openSSH key". Then I tried saving it as both ~/.ssh/mykey.rsa and mykey.dsa (no idea which one it should be). This did not work - tortoise git still says ``` "could not read from remote repository" ``` The problem I guess is that there is no way to know if puttygen is exporting the public or private key - it doesn't give you the option. I have also tried saving as id_rsa and id_dsa, no luck.

Original source