Unfortunately, LibGit2Sharp does not include necessary crypto libraries out of box (https://github.com/libgit2/libgit2sharp/issues/255#issuecomment-212580185).
Use LibGit2Sharp-SSH NuGet package (fork).
private void Run()
{
var url = "ssh://[email protected]/some/repository.git";
var path = @"C:\Temp\some-repository";
LibGit2Sharp.Repository.Clone(url, path, new LibGit2Sharp.CloneOptions { CredentialsProvider = MyCredentialsProvider });
}
private Credentials MyCredentialsProvider(string url, string usernameFromUrl, SupportedCredentialTypes types)
{
var sshDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".ssh");
return new LibGit2Sharp.SshUserKeyCredentials()
{
Username = usernameFromUrl,
Passphrase = string.Empty,
PublicKey = Path.Combine(sshDir, "id_rsa.pub"),
PrivateKey = Path.Combine(sshDir, "id_rsa"),
};
}