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