Linux下使用nodejs ssh登陆到另一台主机

const fs = require('fs');
const child_process = require('child_process');

var workerProcess = child_process.exec('ssh mxl@10.170.15.8 ,
function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
});

  workerProcess.on('exit', function (code) {
  console.log('子进程已退出,退出码 '+code);

});

 如上面的程序我想把密码直接通过这个函数输入进去,而不是在终端输入。怎么实现呢?

直接用ssh的参数中把用户名,密码等配置,然后一起执行