node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -


i wandering whether there valid solution have remote terminal openwrt-box out of nodejs-app?

connecting terminal works: ssh -i ~/.mykeys/id_rsa root@192.168.178.39

busybox v1.23.2 (2015-04-22 23:25:48 utc) built-in shell (ash)

root@openwrt:~#

the only interactive ssh solution nodejs doesn't interactive part described in readme.md following:

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('stdout: ' + data);     }).stderr.on('data', function(data) {       console.log('stderr: ' + 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') }); 

it tested against openssh. a solution setting atop of ssh2 node lib doesn't work. build identify prompt (e.g.)

so next idea had been, execute shell command stdin , stdout child_process

var spawn = require('child_process').spawn;                var ssh    = spawn('ssh', ['-tt', 'root@'+host]);                     process.stdin.resume();                     process.stdin.on('data', function (chunk) {                       ssh.stdin.write(chunk);                     }); 

... hangs first solution.

my last idea exit nodejs-app , execute operating systems ssh command params out of terminated nodejs-app. couldn't find way this. after thinking about, noticed ... error code nothing else comes terminated process. has child_process gains full stdin/stdout/stderr ... right way this?

and work dropbear-servers ?

here can find virtual machine testing against.

if want "interactive part" ssh2, need pipe between remote shell process , local stdin/stdout/stderr not done automatically:

var fs = require('fs'); 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();     });     stream.pipe(process.stdout);     stream.stderr.pipe(process.stderr);     process.stdin.pipe(stream);   }); }).connect({   host: '192.168.178.39',   port: 22,   username: 'root',   privatekey: fs.readfilesync('/home/' + process.env.user + '/.mykeys/id_rsa') }); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -