c# - C# 使用 ssh.net 从 SSH 服务器检索数据时出错
问题描述
当我尝试连接到 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;
}
解决方案
由于 iDRAC CLI 的限制,我使用 plink.exe(PuTTY 的一部分)通过 SSH 连接到它。我认为问题在于您无法修改 iDRAC 上的 sshd_config 文件(它们将其锁定,因此出于安全原因您无法访问底层文件系统)。Plink 允许我做我想做的事,但 PuTTY 需要成为应用程序安装过程的一部分。
推荐阅读
- excel - 密码保护工作表 Excel VBA
- json - 反序列化 JSON 后的 NullPointer
- python - 如何解码“utf-8”中的字符串?
- node.js - 为什么我的 MongoDB ObjectID 没有被识别为 TypeScript 中的类型?
- r - Splitting Strings based on capital letters (R)
- sql - 从用户 - 数据浏览器返回第 10 个和第 100 个帖子 ID 的查询
- nativescript - nativescript-camera-plus 使用屏幕分辨率而不是本机相机的宽度和高度
- encoding - 为什么块之间的 GIF 编码/解码中有这么多填充
- sql-server - 当表/视图链接到 Access 时,为什么我不能在 SQL Server 中进行架构更改?
- aws-lambda - AWS lambda 和数据库