4

Having some trouble using libgit2sharp to pull/push changes to a remote repository using SSH authentication. This remote repository is hosted in GitLab.

Here is the code that I'm using:

using (var repo = new Repository(repoDirectory))
{
    var remote = repo.Network.Remotes["origin"];
    var options = new PushOptions
    {
        CredentialsProvider = (url, user, cred) =>
        {
            var credentials = new SshUserKeyCredentials()
            {
                PrivateKey = @"c:\users\<username>\.ssh\id_rsa",
                PublicKey  = @"c:\users\<username>\.ssh\id_rsa.pub",
                Passphrase = string.Empty,
                Username   = "git"
            };
            return credentials;
        }
    };
    repo.Network.Push(remote, @"refs/heads/master", options);
}

I've put a breakpoint inside the CredentialsProvider delegate and it doesn't get executed. The error message that I get is this:

"Failed to start SSH session: Unable to exchange encryption keys"

Anyone has any idea why I'm getting this message? I'm totally lost here.

LibGit2Sharp v0.25.2, LibGit2Sharp-SSH v1.0.22

  • 2
    I can't find a solution to this either. There's absolutely zero documentation for any of this, and the CredentialsProvider isn't even invoked before that error occurs, so you don't even have the opportunity to specify the ssh files. This seems to be a lower-level protocol error, like a library that simply will not function against the target server. – Triynko Nov 20 '18 at 05:28

0 Answers0