【发布时间】:2021-04-06 16:19:50
【问题描述】:
当我尝试连接到 SSH 服务器(在这种情况下,SSH 服务器是戴尔服务器上的 iDRAC)时,我不断收到以下错误:
Renci.SshNet.Common.SshAuthenticationException
HResult=0x80131500
Message=No suitable authentication method found to complete authentication (publickey,keyboard-interactive).
我找到的所有内容都引用了 SCP,但我没有使用 SCP,因为我没有下载文件。我需要在 iDRAC 上运行命令以获取系统事件日志并将其显示在文本框中。下面的代码由按钮事件处理程序调用(再往下):
public string ConnectSSH(string RemoteHost, string UserName, string PassWord, string sshCommand, out string ServerResponse)
{
using (var client = new SshClient(RemoteHost, 22, UserName, PassWord))
{
client.Connect();
var cmd = client.CreateCommand(sshCommand);
var asyncResult = cmd.BeginExecute();
var outputReader = new StreamReader(cmd.OutputStream);
string output;
while (!asyncResult.IsCompleted)
{
output = outputReader.ReadToEnd();
ServerResponse = output;
}
output = outputReader.ReadToEnd();
ServerResponse = output;
client.Disconnect();
return ServerResponse;
}
}
以及按钮事件处理代码:
private void BtnGetSel_Click(object sender, EventArgs e)
{
RemoteHost = TxtHostName.Text;
UserName = TxtUserName.Text;
PassWord = TxtPassWord.Text;
SshCommand = "racadm getsel -E";
ConnectSSH(RemoteHost, UserName, PassWord, SshCommand, out ServerResponse);
LblServerResponse.Text = ServerResponse;
}
【问题讨论】:
-
您必须提供身份验证方法。 See here
-
我不确定,但我认为您应该指定身份验证方法: var methods = new List
(); methods.Add(new PasswordAuthenticationMethod(UserName, PassWord); var con = new ConnectionInfo(RemoteHost, Port, UserName, methods.ToArray()); using (var client = new SftpClient(con)) { client.Connect(); } -
您可以在该库的文档中查看用法:github.com/sshnet/SSH.NET/#usage