title: Trouble with Multi-Hop SSH with password prompt C#
body: <p>How can I pass a password to an SSH prompt that will not let me send via the command? </p>
  
  <p><strong>This is not working</strong></p>
  
  <pre><code> KeyboardInteractiveAuthenticationMethod DEVICEkauth = new KeyboardInteractiveAuthenticationMethod(DEVICEsshUname);
              PasswordAuthenticationMethod DEVICEpauth = new PasswordAuthenticationMethod(DEVICEsshUname, DEVICEsshPass);
  </code></pre>
  
  <p>I am trying to do a multi-hop ssh connection and it fails on the third hop due to SSH Protocol identification.</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/48759639/">Multi hop SSH through SSH.NET in C#</a> does not solve my
    problem, it did help me get most of the way. This problem is trying to
    do a third hop which does not work.</p>
  </blockquote>
  
  <p>This is via a VeloCloud Gateway connecting to a Velo Edge then connecting to an end device (DiGi Transport)</p>
  
  <p><strong>What I have so far:</strong></p>
  
  <pre><code>    int sssshTimeOut = 1000;
  
      KeyboardInteractiveAuthenticationMethod VCGkauth = new KeyboardInteractiveAuthenticationMethod(VCGsshUname);
      PasswordAuthenticationMethod VCGpauth = new PasswordAuthenticationMethod(VCGsshUname, VCGsshPass);
  
      VCGkauth.AuthenticationPrompt += new EventHandler&lt;AuthenticationPromptEventArgs&gt;(VCGHandleKeyEvent);
  
      SshClient sshVCG = new SshClient(new ConnectionInfo(VCGsshHost, VCGsshPort, VCGsshUname, VCGpauth, VCGkauth));
      if (sssshTimeOut != 0)
      {
          sshVCG.ConnectionInfo.Timeout = TimeSpan.FromSeconds(sssshTimeOut);
      }
  
      void VCGHandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
      {
          foreach (AuthenticationPrompt prompt in e.Prompts)
          {
              if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
              {
                  prompt.Response = VCGsshPass;
              }
          }
      }
  
      KeyboardInteractiveAuthenticationMethod EDGEkauth = new KeyboardInteractiveAuthenticationMethod(EDGEsshUname);
      PasswordAuthenticationMethod EDGEpauth = new PasswordAuthenticationMethod(EDGEsshUname, EDGEsshPass);
  
      EDGEkauth.AuthenticationPrompt += new EventHandler&lt;AuthenticationPromptEventArgs&gt;(EDGEHandleKeyEvent);
      void EDGEHandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
      {
          foreach (AuthenticationPrompt prompt in e.Prompts)
          {
              if (prompt.Request.IndexOf("Password:", StringComparison.InvariantCultureIgnoreCase) != -1)
              {
                  prompt.Response = EDGEsshPass;
              }
          }
      }
  
      KeyboardInteractiveAuthenticationMethod DEVICEkauth = new KeyboardInteractiveAuthenticationMethod(DEVICEsshUname);
      PasswordAuthenticationMethod DEVICEpauth = new PasswordAuthenticationMethod(DEVICEsshUname, DEVICEsshPass);
  
      DEVICEkauth.AuthenticationPrompt += new EventHandler&lt;AuthenticationPromptEventArgs&gt;(DEVICEHandleKeyEvent);
      void DEVICEHandleKeyEvent(Object sender, AuthenticationPromptEventArgs e)
      {
          foreach (AuthenticationPrompt prompt in e.Prompts)
          {
              if (prompt.Request.IndexOf("password:", StringComparison.InvariantCultureIgnoreCase) != -1)
              {
                  prompt.Response = DEVICEsshPass;
              }
          }
      }
  
      Console.WriteLine("Connecting to VCG: "+ VCGsshHost + "");
      sshVCG.Connect();
  
      Console.WriteLine("Sending ARP command to VCG: " + VCGsshHost + "");
      var commandVCG = sshVCG.CreateCommand("arp -n");
      var resultVCG = commandVCG.Execute();
      Console.WriteLine(resultVCG);
  
      Console.WriteLine("");
      Console.WriteLine("");
      Console.WriteLine("Forwarding SSH connection to Edge: " + EDGEsshHost + "");
      var portVCG = new ForwardedPortLocal("127.0.0.1", uintVCGsshPort, EDGEsshHost, uintEDGEsshPort);
      sshVCG.AddForwardedPort(portVCG);
      portVCG.Start();
      if (portVCG.IsStarted)
      {
          Console.WriteLine("Forwarding SSH connection to Edge: Started!");
      }
      else
      {
          Console.WriteLine("Forwarding SSH connection to Edge: seems to have failed.....");
      }
  
      SshClient sshEDGE = new SshClient(new ConnectionInfo(portVCG.BoundHost, (int)portVCG.BoundPort, EDGEsshUname, EDGEpauth, EDGEkauth));
      sshEDGE.Connect();
  
      Console.WriteLine("Sending ARP command to Edge: " + EDGEsshHost + "");
      var commandEDGE = sshEDGE.CreateCommand("arp -n");
      var resultEDGE = commandEDGE.Execute();
      Console.WriteLine(resultEDGE);
  
      Console.WriteLine("");
      Console.WriteLine("");
      Console.WriteLine("Forwarding SSH connection to EndDevice: " + DEVICEsshHost + "");
      var portEDGE = new ForwardedPortLocal("127.0.0.1", uintEDGEsshPort, DEVICEsshHost, uintDEVICEsshPort);
      sshEDGE.AddForwardedPort(portEDGE);
      //sshVCG.AddForwardedPort(portEDGE);
      portEDGE.Start();
      if (portEDGE.IsStarted)
      {
          Console.WriteLine("Forwarding SSH connection to End Device: Started!");
      }
      else
      {
          Console.WriteLine("Forwarding SSH connection to End Device: seems to have failed.....");
      }
  
      SshClient sshDEVICE = new SshClient(new ConnectionInfo(portEDGE.BoundHost, (int)portEDGE.BoundPort, DEVICEsshUname, DEVICEpauth, DEVICEkauth));
      //SshClient sshDEVICE = new SshClient(new ConnectionInfo(portVCG.BoundHost, (int)portVCG.BoundPort, DEVICEsshUname, DEVICEpauth, DEVICEkauth));
      //SshClient sshDEVICE = new SshClient(portEDGE.BoundHost, (int)portEDGE.BoundPort, DEVICEsshUname, DEVICEsshPass);
      sshDEVICE.Connect();
  
      Console.WriteLine("");
      Console.WriteLine("");
      Console.WriteLine("Sending HW command to End Device: " + DEVICEsshHost + "");
      var commandDEVICE = sshDEVICE.CreateCommand("hw");
      var resultDEVICE = commandDEVICE.Execute();
      Console.WriteLine(resultDEVICE);
  </code></pre>
  
  <p>I am expecting the SSH to connect to the VGC, then the Edge, then the end device, and run a command.</p>
  
  <p>This process gets just as far if I do it via Plink...</p>
  
  <p><strong>Error:</strong> </p>
  
  <blockquote>
    <p>Renci.SshNet.Common.SshConnectionException: 'Server response does not
    contain SSH protocol identification.'</p>
  </blockquote>
  
  <p><strong>Plink</strong></p>
  
  <pre><code>Plink Window 1
  
  C:\Users\ncarter&gt;Plink.exe -ssh -L 4000:xxx.xxx.xxx.2:22 xxxxxxx@xx.xx.xxx.85 -P 10444
  Using username "xxxxxxx".
  xxxxxx@xx.xx.xxx.85's password:
  Welcome to Velocloud VCG (GNU/Linux 3.13.0-160-generic x86_64)
  
   * Documentation:  https://help.ubuntu.com/
  
    Get cloud support with Ubuntu Advantage Cloud Guest:
      http://www.ubuntu.com/business/services/cloud
  
  Last login: Fri Oct 11 18:44:59 2019 from xxx.xxx.x.42
  ]0;xxxxxx@xxxx-xxlab: ~xxxxxx@xxxx-xxlab:~$
  
  Plink Window 2
  
  C:\Users\ncarter&gt;Plink.exe -ssh -L 8001:xxx.xxx.xx.1:xxx97 xxxx@127.0.0.1 -P 4000
  Using username "xxxxx".
  Using keyboard-interactive authentication.
  Password:
  
  
  BusyBox v1.23.2 (2018-10-19 16:11:09 UTC) built-in shell (ash)
  
    _    __     __      ________                __
   | |  / /__  / /___  / ____/ /___  __  ______/ /
   | | / / _ \/ / __ \/ /   / / __ \/ / / / __  /
   | |/ /  __/ / /_/ / /___/ / /_/ / /_/ / /_/ /
   |___/\___/_/\____/\____/_/\____/\__,_/\__,_/
  
                                    VeloCloud Inc.
  ------------------------------------------------
  velocloud Test-Edge-1:~# [6narp
  Address                  HWtype  HWaddress           Flags Mask            Iface
  192.168.11.1             ether   00:04:2d:07:b9:1f   C                     ge4
  xx.xxx.xxx.227           ether   50:7b:9d:35:1d:12   C                     br-network1
  SIP-xxxx.xxx             ether   80:5e:c0:29:61:ad   C                     br-network1
  198.19.0.33              ether   00:50:56:91:ff:2e   C                     ge3
  198.19.0.1               ether   90:6c:ac:bb:c9:8c   C                     ge3
  198.19.0.32              ether   00:50:56:91:7f:da   C                     ge3
  xxx.xxx.xx.4             ether   50:7b:9d:35:1d:12   C                     br-network1
  velocloud Test-Edge-1:~# [6nssh -p xxx97 xxxxxx@192.168.11.1 -t 'hw'
  xxxxxx@192.168.11.1's password:
  
  SN:506143
  Welcome. Your access level is SUPER
  
  ss506143&gt;
  Serial Number: 506143
  HW Rev: 3205b
  MAC 0: 00042d07b91f
  MAC 1: 00042df7b91f
  MAC 2: 00042de7b91f
  MAC 3: 00042dd7b91f
  MAC 4: 00042dc7b91f
  MAC 5: 000000000000
  MAC 6: 000000000000
  Model: WR11
  Part#: WR11-L800-DE1-SU
  RAM: 64 MB
  OK
  
  ss506143&gt;Connection to 192.168.11.1 closed.
  velocloud Test-Edge-1:~# [6n
  
  </code></pre>