更新时间: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());