且构网

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

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

更新时间:2022-02-27 21:55:08

您的问题在这里吗?就是您仍在使用密码,即使密码为空。删除以下行:

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());