asp.net - .NET SSH pbrun su

标签 asp.net .net ssh ssh.net

我正在使用 SSH.NET 从我的 .net 应用程序连接到 Linux 服务器。我执行的每个命令都按预期完成,但 pbrun su - myaccount 除外。

在调试时,当执行 pbrun su - myaccount 命令时,调试器中的箭头消失,并且控制权永远不会返回到 Visual Studio,因此需要我手动停止调试应用程序。

最佳答案

如果问题是 pbrun 要求标准输入中的某些内容(密码、原因等),您可以创建一个带有由您控制的流的 shell 并在其中写入。

简单的例子:

using System;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var connectionInfo = new Renci.SshNet.PasswordConnectionInfo("ancardia.us.to", "adom", "adom");
            var ssh = new Renci.SshNet.SshClient(connectionInfo);

            ssh.Connect();

           var shell = ssh.CreateShell(Console.OpenStandardInput(), Console.OpenStandardOutput(), Console.OpenStandardOutput());
           shell.Start();

       while (true) {
            Console.Read();
            }

        }


    }
}

enter image description here

关于asp.net - .NET SSH pbrun su,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38128713/

相关文章:

Python Paramiko 将 CTRL+C 发送到 ssh shell

c# - 当 session 过期时, session 管理器不会将我注销,HTTPContext.Current 为 Null

asp.net - 带有自定义数据的 web api 发布图像

c# - (datatype, datatype) x = (value, value) 在 C# 中是什么意思? x 的实际数据类型是什么?

c# - Async/Await vs Parallel.For,在这种情况下哪个更好?

objective-c - 如何将 RSA key 转换为 ssh-rsa

asp.net - 如何从异常中获取更多详细信息?

.net - 覆盖 AuthorizeAttribute.AuthorizeCore 时为 "cannot set status after HTTP headers"

.net - .NET 是否有验证框架?

scala - 使用 scala 使用用户名和密码进行 SSH