Reputation: 1947
I can't seem to make this library to work. I'm doing something pretty straightforward but still I can't manage to do it.
client.Connect();
client.RunCommand("sudo passwd test");
Thread.Sleep(1000);
client.RunCommand("testtest");
Thread.Sleep(1000);
client.RunCommand("12345");
Thread.Sleep(1000);
client.RunCommand("12345");
bool primera = true;
client.Disconnect();
If I try then to login with test using the credentials just posted it fails. But if I do the same commands through normal SSH through my terminal I can log in. Why SSH.NET is not executing those commands?
Upvotes: 1
Views: 2331
Reputation: 840
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");
Upvotes: 3