I'm looking to automate password change that's accomplished manually as such:
plink -ssh user@host changepass
user@host's password:
Access granted. Press Return to begin session.
Enter current password:
...
My understanding is that I am unable to accomplish this using RunCommand
because it's not interactive and will not allow me to further specify the current password, hit enter, then the new password, etc. From what I understand I would have to use CreateShellStream
to emulate a shell. When I try to do something like this:
using (var client = new SshClient(host, username, password))
{
client.Connect();
ShellStream shellStream = client.CreateShellStream(string.Empty, 0, 0, 0, 0, 0);
Console.Write(SendCommand("changepass", shellStream));
client.Disconnect();
}
The result is The command executed is invalid.....
which is the same thing that I get if I attempt to use plink without specifying the command inline:
plink -ssh -t user@host
Using username "user".
-- Pre-authentication banner message from server: ----------------------------
user@host's password:
Access granted. Press Return to begin session.
The command executed is invalid.....
I am wondering if my approach is invalid and whether this can be accomplished with SSH.NET. If not what would be a good way to do this from C#?