Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在节点中将pty与ssh2一起使用,以使用sudo执行命令_Node.js_Ssh_Libssh2 - Fatal编程技术网

Node.js 在节点中将pty与ssh2一起使用,以使用sudo执行命令

Node.js 在节点中将pty与ssh2一起使用,以使用sudo执行命令,node.js,ssh,libssh2,Node.js,Ssh,Libssh2,我需要使用node.js的npmssh2模块通过ssh启动sudo命令; 仅阅读模块的文档,我不知道如何使用pty选项: 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 e

我需要使用node.js的npmssh2模块通过ssh启动sudo命令; 仅阅读模块的文档,我不知道如何使用pty选项:

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
});

有人能解释一下这个的正确用法吗?

您必须解析sudo提示符的
流输出。此时,您必须
stream.write(密码+'\n')。做所有这些的替代方法是修改
/etc/sudoers
,这样登录的用户就可以在没有密码的情况下为特定的程序/脚本/任何东西执行sudo。

我认为您应该放置
流。write(password+'\n')就在
流的后面。在('exit',…
行。

我不能让它工作。我如何/在哪里添加
流。write(password+'\n');