使用LibGit2Sharp-SSH克隆GitHub仓库时遭遇SSH会话启动失败(无法交换加密密钥)问题求助
使用LibGit2Sharp-SSH克隆GitHub仓库时遭遇SSH会话启动失败(无法交换加密密钥)问题求助
我现在尝试用LibGit2Sharp-SSH.NativeBinari(v1.0.15)和LibGit2Sharp-SSH-updated-libssh(v1.0.25)这两个库,通过下面的代码把GitHub上的仓库克隆到本地:
string repoURL = "ssh://git@github.com/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; }
但是运行后一直报错:Failed to start SSH session: Unable to exchange encryption keys
不过我在命令行里运行ssh -T git@github.com是正常的,返回:
Hi MyUser! You've successfully authenticated, but GitHub does not provide shell access.
而且用TortoiseGit的Git克隆功能也能成功,参数是:
URL = ssh://git@github.com/MyUser/MyRepo.git
Directory = D:\Github-Repositories\MyRepo
Load Putty Key = C:\Users\MyUser.ssh\id_rsa.ppk
直接用Git命令行克隆也没问题,命令是:
git clone git@github.com/MyUser/MyRepo.git D:\Github-Repositories\MyRepo
有没有大佬能帮忙看看代码哪里出问题了?提前谢谢大家!
备注:内容来源于stack exchange,提问作者Idoneus
相关产品推荐
相关产品推荐

