ssh into a server using js and to initiate a shell-

Viewed 27

I am trying to ssh to a linux machine using java script. I am able to connect to the server initaite a shell and run commands but I wanted to stay on the server where I ssh , I wanted it like a normal ssh which returns a shell.

With the below script , it connects to the server and runs the command I give. But then it returns to the next line and does nothing . Just blank. Please help.

const { readFileSync } = require('fs');

const { Client } = require('ssh2');

const conn = new Client();
conn.on('ready', () => {
  console.log('Client :: ready');
  conn.shell((err, stream) => {
    if (err) throw err;
    stream.on('close', () => {
      console.log('Stream :: close');
      conn.end();
    }).on('data', (data) => {
      console.log('OUTPUT: ' + data);
    });
    // stream.end('')
  });
}).connect({
    host: '',
    port: 22,
    username: 'abilash',
    privateKey: readFileSync('/my/file')
  });

Pls help!!!

0 Answers
Related