Trouble Authenticating/Communicating using SSH with libgit2sharp

389 views Asked by At

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

0

There are 0 answers