无法连接到AIX(UNIX)与SSH.NET库中 - 错误:值不能为空 [英] Unable to connect to AIX(Unix) box with SSH.NET Library - Error : Value cannot be null

查看:1115
本文介绍了无法连接到AIX(UNIX)与SSH.NET库中 - 错误:值不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图连接到一个 AIX 框和使用的 SSH.NET 库执行某些命令。 以下是code snipplet

I am trying to connect to an AIX box and execute some commands using SSH.NET library. The following is the code snipplet

KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password);

ConnectionInfo connectionInfo = new(ConnectionInfo(servername, 22, username, pauth,kauth);
SshClient sshClient = new SshClient(connectionInfo);
sshClient.Connect();
SshCommand sshCommand = sshClient.RunCommand("mpstat");
Console.WriteLine(sshCommand.Result);
Console.ReadKey();

我碰到下面的异常消息:当我试图连接在该行 sshClient.Connect()

I get the following exception message when I try to connect at the line sshClient.Connect()

{值不能为空\ r \ n参数名:数据}

{"Value cannot be null.\r\nParameter name: data"}

该堆栈跟踪

   at Renci.SshNet.KeyboardInteractiveAuthenticationMethod.Authenticate(Session session)
   at Renci.SshNet.ConnectionInfo.Authenticate(Session session)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.Connect()

我有信心,我通过证书是有效的,因为我的能够登录在使用的 腻子 客户端使用相同的凭证。任何想法?

I am confident that the credentials I pass are valid since I am able to log-in using the PuTTY client with the same credentials. Any ideas?

推荐答案

我发现了一些研究后的溶液。希望它可以帮助别人。

I found the solution after some research. Hope it helps somebody else.

键盘交互认证应使用和 AuthenticationPrompt 事件应该用下面的函数来覆盖

The keyboard interactive authentication should be used and AuthenticationPrompt event should be overridden with the following function

void HandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
{
    foreach (AuthenticationPrompt prompt in e.Prompts)
    {
        if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
        {
            prompt.Response = password;
        }
    }
}

函数调用code:

The function call code :

KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(username);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(username, password);

kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(HandleKeyEvent);

ConnectionInfo connectionInfo = new ConnectionInfo(serverName, port, username, pauth, kauth);

sshClient = new SshClient(connectionInfo);
sshClient.Connect();

这篇关于无法连接到AIX(UNIX)与SSH.NET库中 - 错误:值不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆