title: how to create interactive ssh terminal and enter commands from the browser using Node JS in a Meteor app
body: <p>I'm trying to create a web page where the user can authenticate to a remote server via ssh with username/password, and then interact with the remote server.</p>
  
  <p>I'm not looking to create a full interactive terminal: the app server will execute a limited set of commands based on user input and then pass the responses back to the browser.</p>
  
  <p>Different users should interact with different ssh sessions.</p>
  
  <p>My app is built in Meteor 1.8.1, so the back end runs under Node JS, version 9.16.0. It's deployed to Ubuntu using Phusion Passenger.</p>
  
  <p>I have looked at several packages that can create an interactive ssh session but I am missing something basic about how to use them.</p>
  
  <p>For example <a href="https://github.com/mscdex/ssh2#start-an-interactive-shell-session" rel="nofollow noreferrer">https://github.com/mscdex/ssh2#start-an-interactive-shell-session</a></p>
  
  <p>The example shows this code:</p>
  
  <pre><code>var Client = require('ssh2').Client;
  
  var conn = new Client();
  conn.on('ready', function() {
    console.log('Client :: ready');
    conn.shell(function(err, stream) {
      if (err) throw err;
      stream.on('close', function() {
        console.log('Stream :: close');
        conn.end();
      }).on('data', function(data) {
        console.log('OUTPUT: ' + data);
      });
      stream.end('ls -l\nexit\n');
    });
  }).connect({
    host: '192.168.100.100',
    port: 22,
    username: 'frylock',
    privateKey: require('fs').readFileSync('/here/is/my/key')
  });
  </code></pre>
  
  <p>This example connects to the remote server, executes a command 'ls' and then closes the session. It isn't 'interactive' in the sense I'm looking for. What I can't see is how to keep the session alive and send a new command?</p>
  
  <p><a href="https://github.com/billchurch/webssh2" rel="nofollow noreferrer">This example</a> of a complete terminal looks like overkill for my needs, and I won't be using Docker.</p>
  
  <p><a href="https://stackoverflow.com/questions/38689707/connecting-to-remote-ssh-server-via-node-js-html5-console">This example</a> uses socket.io and I'm not sure how that would interact with my Meteor app? I'm currently using Meteor methods and publications to pass information between client and server, so I'd expect to need a "Meteor-type" solution using the Meteor infrastructure?</p>
  
  <p>child_process.spawn works but will only send a single command, it doesn't maintain a session.</p>
  
  <p>I know other people have asked similar questions but I don't see a solution for my particular case. Thank you for any help.</p>