Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET SSH pbrun su

I'm connecting to a linux server from my .net application using SSH.NET. Each command that I execute completes as expected with the exception of pbrun su - myaccount.

While debugging, when the pbrun su - myaccount command is executed, the arrow in the debugger disappears and control is never returned to visual studio, thus requiring me to manually stop debugging the application.

like image 487
HendPro12 Avatar asked Jun 30 '16 16:06

HendPro12


1 Answers

If the problem is that pbrun is asking for something in stdin (password, reason, etc) you can create a shell with streams controled by you and write in it.

Simple example:

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

like image 147
jlvaquero Avatar answered Nov 08 '22 15:11

jlvaquero