试图通过用户名和私钥仅使用当前的ssh.net库进行身份验证。我无法从用户那里获得密码,所以这是不可能的。ssh.net仅通过私钥进行身份验证
这是我现在正在做的事情。
Renci.SshNet.ConnectionInfo conn = new ConnectionInfo(hostName, port, username, new AuthenticationMethod[]
{
new PasswordAuthenticationMethod(username, ""),
new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[] { new PrivateKeyFile(privateKeyLocation, "") }),
});
using (var sshClient = new SshClient(conn))
{
sshClient.Connect();
}
现在,如果i。从AuthenticationMethod[]
阵列I得到一个异常用于发现合适的认证方法除去PasswordAuthenticationMethod
。如果我试图通过(主机名,端口,用户名,密钥文件2)这样的
var keyFile = new PrivateKeyFile(privateKeyLocation);
var keyFile2 = new[] {keyFile};
再次,找不到合适的方法。
看来我必须使用ConnectionInfo
对象,因为我上面列出,但似乎它评估PasswordAuthenticationMethod
和无法登陆(因为我不提供密码),从来没有评估PrivateKeyAuthMethod
...这是案子?有没有其他的方法来验证只有用户名或主机名和私钥使用ssh.net lib?
啊,是的,这对我有效,谢谢! –