2016-06-30 37 views
8

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

尽管调试,当pbrun苏 - 执行我的帐户命令,在调试器中箭头消失,控制永远不会返回到Visual Studio,因此要求我手动停止调试应用程序。

+0

的'su'命令可能是等待一个密码。如果你正在查看标准输出你不会看到这个,因为提示符'Password:'被发送到标准错误。在[这个](http://stackoverflow.com/questions/30079526/how-to-write-to-stdin-read-from-stdout-of-an-ssh-connected-remote-process-renc#36360010)交你可以直接写shell到标准输入。 – AxelWass

+0

@AxelWass为什么会是期待一个密码,如果运行在终端同pbrun su命令时,一个没有提示或要求? – HendPro12

+0

我在这里猜测,但也许ssh用户和本地用户不一样?也许使用'须藤visudo'有助于为[这里](http://askubuntu.com/questions/470383/how-to-avoid-prompt-password-for-sudo#470466)。 – AxelWass

回答

1

如果问题是pbrun是要求在标准输入的东西(密码,原因等),你可以创建你所controled流的外壳,并在其中写。

简单的例子:

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

+0

我用我的服务器详细信息示例,它显示控制台中的远程终端。但是,如前所述,当我执行pbrun su - myaccount时,它会成功更改用户,并且不需要密码, – HendPro12