The problem is because after you run client.RunCommand("sudo passwd test");
a program is running, waiting for input. The RunCommand
method won't actually run the command until after the program returns.
I encountered the same problem when trying to run su - <login>
and found the following workaround...
Shell = Client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
Reader = new StreamReader(Shell);
Writer = new StreamWriter(Shell);
Writer.AutoFlush = true;
Writer.Write("su - " + login2 + "\n");
while (true)
{
var output = Reader.ReadLine();
if (output.EndsWith("Password: "))
{
break;
}
}
Writer.Write(password2 + "\n");