且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SSH.NET 仅通过私钥进行身份验证(公钥身份验证)

更新时间:2022-03-04 21:22:37

您的问题是您仍在使用密码,即使它是空白的.删除这一行:

Your problem here is that you're still using a password, even though it is blank. Remove this line:

new PasswordAuthenticationMethod(username, ""), 

这对我来说非常有效:

var pk = new PrivateKeyFile(yourkey);
var keyFiles = new[] { pk };

var methods = new List<AuthenticationMethod>();
methods.Add(new PrivateKeyAuthenticationMethod(UserName, keyFiles));

var con = new ConnectionInfo(HostName, Port, UserName, methods.ToArray());