最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Libgit2sharp-ssh: Failed to start SSH session: Unable to exchange encryption keys - Stack Overflow

programmeradmin4浏览0评论

I'm trying to clone a repo to my computer using the following code by using LibGit2Sharp-SSH.NativeBinari (v 1.0.15) and LibGit2Sharp-SSH-updated-libssh (v 1.0.25)

string repoURL = "ssh://[email protected]/MyUser/MyRepo.git"; 
string prm_localpath = @"D:\Github-Repositories\MyRepo"; // Replace with your desired 
local path
string privateKeyPath = @"C:/Users/MyUser/.ssh/id_rsa"; // Replace with your private 
 key path
string publicKeyPath = @"C:/Users/MyUser/.ssh/id_rsa.pub"; // Usually, the public key 
has .pub extension
string passphrase = string.Empty; // If your key has a passphrase, enter it here
//git clone 
try
{
    
    var sshKey = new SshUserKeyCredentials
    {
        Username = "git",
        PrivateKey = privateKeyPath,
        PublicKey = publicKeyPath,
        Passphrase = passphrase
    };
    
    Repository.Clone(repoURL, prm_localpath, new CloneOptions
    {
        
        CredentialsProvider = (_url, _user, _cred) => sshKey
    });

    return "Cloned successfully";

}
catch (LibGit2SharpException ex)
{
    return ex.Message;
}
catch (Exception ex)
{
    return ex.Message;
}

and I get "Failed to start SSH session: Unable to exchange encryption keys" From command prompt: $ ssh -T [email protected] Hi MyUser! You've successfully authenticated, but GitHub does not provide shell access. It is working fine if I do it from Windows Explorer, "Git_clone" using TortoiseGit, it's working with the following params:

URL = ssh://[email protected]/MyUser/MyRepo.git

Directory = D:\Github-Repositories\MyRepo

Load Putty Key = C:\Users\MyUser.ssh\id_rsa.ppk

also if I do it from command prompt:

`git clone [email protected]/MyUser/MyRepo.git D:\Github-Repositories\MyRepo`

Thanks in advance!

I'm trying to clone a repo to my computer using the following code by using LibGit2Sharp-SSH.NativeBinari (v 1.0.15) and LibGit2Sharp-SSH-updated-libssh (v 1.0.25)

string repoURL = "ssh://[email protected]/MyUser/MyRepo.git"; 
string prm_localpath = @"D:\Github-Repositories\MyRepo"; // Replace with your desired 
local path
string privateKeyPath = @"C:/Users/MyUser/.ssh/id_rsa"; // Replace with your private 
 key path
string publicKeyPath = @"C:/Users/MyUser/.ssh/id_rsa.pub"; // Usually, the public key 
has .pub extension
string passphrase = string.Empty; // If your key has a passphrase, enter it here
//git clone 
try
{
    
    var sshKey = new SshUserKeyCredentials
    {
        Username = "git",
        PrivateKey = privateKeyPath,
        PublicKey = publicKeyPath,
        Passphrase = passphrase
    };
    
    Repository.Clone(repoURL, prm_localpath, new CloneOptions
    {
        
        CredentialsProvider = (_url, _user, _cred) => sshKey
    });

    return "Cloned successfully";

}
catch (LibGit2SharpException ex)
{
    return ex.Message;
}
catch (Exception ex)
{
    return ex.Message;
}

and I get "Failed to start SSH session: Unable to exchange encryption keys" From command prompt: $ ssh -T [email protected] Hi MyUser! You've successfully authenticated, but GitHub does not provide shell access. It is working fine if I do it from Windows Explorer, "Git_clone" using TortoiseGit, it's working with the following params:

URL = ssh://[email protected]/MyUser/MyRepo.git

Directory = D:\Github-Repositories\MyRepo

Load Putty Key = C:\Users\MyUser.ssh\id_rsa.ppk

also if I do it from command prompt:

`git clone [email protected]/MyUser/MyRepo.git D:\Github-Repositories\MyRepo`

Thanks in advance!

Share Improve this question asked yesterday IdoneusIdoneus 861 silver badge8 bronze badges 4
  • I cannot even find the LibGit2Sharp-SSH.NativeBinaries package for version 1.0.15. Both packages on nuget look outdated, you'd better consider using LibGit2Sharp. – shingo Commented yesterday
  • I would but I need ssh authentication. The project type I create is a c# library – Idoneus Commented 18 hours ago
  • 0.31.0 says it supports ssh. – shingo Commented 17 hours ago
  • I created a new project, using 0.31.0 version and I get CS0246: The type or namespace name "SshUserKeyCredentials" could not be found (are you missing a using directive or an assembly reference?) – Idoneus Commented 12 hours ago
Add a comment  | 

1 Answer 1

Reset to default 0

I created a new project, using 0.31.0 version of LibGit2Sharp. The solutions is that there is no need to setup the CloneOptions, just Repository.Clone(repoURL, localPath); and, obviously, the SSH key must be set properly in git.

发布评论

评论列表(0)

  1. 暂无评论