我正在尝试在 C# 中创建一个简单的 SSH 客户端。这是我现在的代码:
using Renci.SshNet;
public static void Main(string[] args)
{
AuthenticationMethod method = new PasswordAuthenticationMethod("pi", "raspberry");
ConnectionInfo connection = new ConnectionInfo("192.168.91.134", "pi", method);
SshClient client = new SshClient(connection);
if (!client.IsConnected)
{
Console.WriteLine("Not Connected...");
client.Connect();
}
while (true)
{
string command = Console.ReadLine();
SshCommand response = client.RunCommand(command);
Console.WriteLine(response.Result);
}
}
问题:
sudo su command给个密码就不行了。。。(将来我想将输出添加到列表框并从 winForms 应用程序中的 texbox 获取输入)
预先感谢您的帮助
请您参考如下方法:
在你想实现一个 SSH 终端客户端(如 PuTTY)时,你需要使用 SSH“shell” channel 。
在 SSH.NET 中,使用 SshClient.CreateShell或 SshClient.CreateShellStream ,而不是 SshClient.RunCommand .




