如何在节点JS中通过ssh执行sudo命令? [英] How do i execute sudo command over ssh in node JS.?

查看:135
本文介绍了如何在节点JS中通过ssh执行sudo命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了remote-exec和node-ssh软件包,但是两者的结果与下面提到的相同.

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

它返回错误:

[错误:554.xxx.xxx.xxx:sudo adduser testuser [出口1]]

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

sudo:抱歉,您必须有一个tty才能运行sudo

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

请告知如何使用节点js运行sudo命令.

Please advise how to run sudo command using node js.

推荐答案

在/etc/sudoers文件中的行下方注释.

Comment below line in /etc/sudoers file.

#默认必填项

这篇关于如何在节点JS中通过ssh执行sudo命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆