我需要使用npm ssh2模块为node.js启动sudo over ssh的命令; 只读取模块的文档,我无法弄清楚如何使用PTY选项:在节点中使用pty和ssh2与sudo执行命令
ssh.on('ready', function() {
//not working sudo command:
ssh.exec('cd /var/www/website && sudo mkdir myDir', { pty: true }, function(err, stream) {
if (err) throw err;
stream.on('exit', function(code, signal) {
console.log('exit code: ' + code + ' signal: ' + signal);
ssh.end();
});
});
}).connect({
host: configuration.sshAddress,
port: 22,
username: configuration.sshUser,
password: configuration.sshPass
});
有人能解释的正确使用呢?
我不能得到这个工作。如何/在哪里添加'stream.write(密码+'\ n');' – user1513388 2017-11-03 17:01:38