SSH.NET passwd未执行 [英] SSH.NET passwd not executing

查看:98
本文介绍了SSH.NET passwd未执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法使该库正常工作. 我正在做一些非常简单的事情,但仍然无法做到.

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();

如果我尝试使用刚刚发布的凭据登录测试,则失败.但是,如果我通过终端通过普通SSH执行相同的命令,则可以登录. 为什么SSH.NET不执行这些命令?

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?

推荐答案

问题是因为运行client.RunCommand("sudo passwd test");之后,程序正在运行,等待输入.直到程序返回后,RunCommand方法才真正运行命令.

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.

尝试运行su - <login>时遇到了相同的问题,并发现以下解决方法...

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");

这篇关于SSH.NET passwd未执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆