2

Trying to put together a sample project cloning a repository (hosted in GOGS) using SSH and am getting the following error:

Failed to start SSH session: Unable to exchange encryption keys

I'm on windows, the keys are generated using ssh-keygen, and I have the following nuget packages referenced

  • LibGit2Sharp 0.25.3
  • LibGit2Sharp.NativeBinaries 1.0.235
  • LibGit2Sharp-SSH 1.0.22
  • LibGit2Sharp-SSH.NativeBinaries 1.0.14

We're able to pull files from a test bit bucket account, but not from the GOGS repository url, using code like the following (the same keys have been uploaded to both accounts).

var co = new CloneOptions
{
        CredentialsProvider = (_url, _user, _cred) => new SshUserKeyCredentials()
        {
                PrivateKey = @"C:\Users\username\.ssh\keygen\gen",
                PublicKey = @"C:\Users\username\.ssh\keygen\gen.pub",
                Passphrase = string.Empty,
                Username = "git"

        },
};
Repository.Clone("ssh://git@<site_url>:443/Project/Project.git ", TestPath, co);

I'd also add that we can clone from both urls using a variety of git clients (git exe, tortoise git, gitkraken) without issue. Also we can connect over https with username and password with LibGit2Sharp.

Things I've tried so far:

  1. Generating new keys with ssh-keygen
  2. Converting the private key file to openssh using puttygen > Conversions > Export OpenSSH
  3. Converting the private key to PEM format using "openssl rsa -in key-out key.pem"
  4. Made sure that the Public key was single line, starting with type, followed by base64 key, no comment at the end
  • I think LibGit2Sharp-SSH supersedes LibGit2Sharp. My code compiles fine with one or the other. If you've installed both, you might be referencing one but not the other. – Triynko Nov 19 '18 at 22:59
  • 1
    So I took out references to LibGit2Sharp and its binaries from my project and am now building with just the -SSH libraries and I'm still getting the same errors. Thanks for the idea though! – matt.rothmeyer Nov 29 '18 at 23:23

0 Answers0