How do i execute sudo command over ssh in node JS.?

余生长醉 提交于 2019-12-06 14:05:33

问题


I tried remote-exec and node-ssh packages, but both are resulting the same as mentioned below.

var rexec = require('remote-exec');

var connection_options = {
       port: 22,
       username: 'user', 
       privateKey: require('fs').readFileSync('privateKey/file.pem'),
       passphrase:''};

var hosts = [
    '54.xxx.xxx.xxx'
];

var cmds = [
   'sudo adduser testuser'
];

rexec(hosts, cmds, connection_options, function(err){

    if (err) {
        console.log(err);
    } else {
        console.log('Great Success!!');
    }
});

It returns the error :

[Error: 554.xxx.xxx.xxx : sudo adduser testuser [Exit 1]]

sudo: sorry, you must have a tty to run sudo

Please advise how to run sudo command using node js.


回答1:


Comment below line in /etc/sudoers file.

#Defaults requiretty



来源:https://stackoverflow.com/questions/44840459/how-do-i-execute-sudo-command-over-ssh-in-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!