2016-06-30 30 views
8

私はSSH.NETを使用している.netアプリケーションからLinuxサーバーに接続しています。 pbrun su - myaccountを除いて、私が実行する各コマンドは期待どおりに完了します。.NET SSH pbrun su

pbrun su - myaccountコマンドが実行されると、デバッガの矢印が消えて制御がVisual Studioに返されないため、アプリケーションのデバッグを手動で停止する必要があります。

+0

'su'コマンドは、おそらくパスワードを待っています。あなたがstdoutを見ているなら、これは見えません。プロンプト 'Password:'がstderrに送られているからです。 [this](http://stackoverflow.com/questions/30079526/how-to-write-to-stdin-read-from-stdout-of-an-ssh-connected-remote-process-renc#36360010)投稿シェル標準に書き込むことができます。 – AxelWass

+0

@AxelWassターミナルで同じpbrun suコマンドを実行するときにプロンプ​​トが表示されない、または必要でないと、なぜパスワードが必要になるのですか? – HendPro12

+0

私はここで推測していますが、おそらくsshユーザーとローカルユーザーが同じではありませんか?おそらく 'sudo visudo'を使って[ここ](http://askubuntu.com/questions/470383/how-to-avoid-prompt-password-for-sudo#470466)のようになります。 – AxelWass

答えて

1

pbrunがstdin(パスワード、理由など)で何かを要求しているという問題がある場合は、ストリームが制御されたシェルを作成して書き込むことができます。

簡単な例:

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

関連する問題