【发布时间】:2020-09-17 17:53:14
【问题描述】:
我希望将手动完成的密码更改自动化:
plink -ssh user@host changepass
user@host's password:
Access granted. Press Return to begin session.
Enter current password:
...
我的理解是,我无法使用 RunCommand 完成此操作,因为它不是交互式的,并且不允许我进一步指定当前密码、按 Enter 键,然后是新密码等。据我所知,我会使用CreateShellStream 模拟外壳。当我尝试做这样的事情时:
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 command executed is invalid.....,这与我尝试使用 plink 而不指定内联命令时得到的结果相同:
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.....
我想知道我的方法是否无效以及这是否可以通过 SSH.NET 完成。如果不是,那么从 C# 中执行此操作的好方法是什么?
【问题讨论】: