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

Venkatesh Kuppusamy

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.

Venkatesh Kuppusamy

Comment below line in /etc/sudoers file.

#Defaults requiretty

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to execute a remote command over ssh with arguments?

From Dev

How do I execute a command string in BASH?

From Dev

Use pty with ssh2 in node to execute command with sudo

From Dev

Execute commands as different user via sudo over SSH in a justfile

From Dev

How can I blank the screen from the command line over SSH?

From Dev

How do I execute Node JS function in order

From Dev

Execute commands as different user via sudo over SSH in a justfile

From Dev

How can I blank the screen from the command line over SSH?

From Dev

How do I execute symbolic linked files in node.js?

From Dev

How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?

From Dev

SSH: execute sudo command

From Dev

How to remote execute ssh command a sudo command without password

From Dev

How do I tunnel SSH over SSH?

From Dev

How can I run detached command with sudo over ssh?

From Dev

How do I execute a command on a specific screen?

From Dev

How do I execute a command in each subdirectory?

From Dev

how do I execute "node server.js" in codelab?

From Dev

How to execute a command over ssh and store the value in a variable

From Dev

execute command over ssh connection

From Dev

How do I execute a xfconf-query command from a bash script launched with sudo?

From Dev

execute remote command over ssh strange behaviour

From Dev

How do I transfer files over ssh after sudo?

From Dev

How do I execute a remote alias over an SSH?

From Dev

How do i execute any command inline ssh as if I'm typing it manually but direct output to local machine?

From Dev

how can I execute command through ssh, remote is windows

From Dev

How can I execute SSH command with output pagination Heredoc

From Dev

Execute a sudo NOPASSWD command remotely via SSH

From Dev

how do I escape quote in ssh command?

From Dev

Python: How to execute more than 1 command over SSH without loggin in every command

Related Related

  1. 1

    How to execute a remote command over ssh with arguments?

  2. 2

    How do I execute a command string in BASH?

  3. 3

    Use pty with ssh2 in node to execute command with sudo

  4. 4

    Execute commands as different user via sudo over SSH in a justfile

  5. 5

    How can I blank the screen from the command line over SSH?

  6. 6

    How do I execute Node JS function in order

  7. 7

    Execute commands as different user via sudo over SSH in a justfile

  8. 8

    How can I blank the screen from the command line over SSH?

  9. 9

    How do I execute symbolic linked files in node.js?

  10. 10

    How do I execute a remote shell script over SSH and be prompted for passwords by commands that require it in that script?

  11. 11

    SSH: execute sudo command

  12. 12

    How to remote execute ssh command a sudo command without password

  13. 13

    How do I tunnel SSH over SSH?

  14. 14

    How can I run detached command with sudo over ssh?

  15. 15

    How do I execute a command on a specific screen?

  16. 16

    How do I execute a command in each subdirectory?

  17. 17

    how do I execute "node server.js" in codelab?

  18. 18

    How to execute a command over ssh and store the value in a variable

  19. 19

    execute command over ssh connection

  20. 20

    How do I execute a xfconf-query command from a bash script launched with sudo?

  21. 21

    execute remote command over ssh strange behaviour

  22. 22

    How do I transfer files over ssh after sudo?

  23. 23

    How do I execute a remote alias over an SSH?

  24. 24

    How do i execute any command inline ssh as if I'm typing it manually but direct output to local machine?

  25. 25

    how can I execute command through ssh, remote is windows

  26. 26

    How can I execute SSH command with output pagination Heredoc

  27. 27

    Execute a sudo NOPASSWD command remotely via SSH

  28. 28

    how do I escape quote in ssh command?

  29. 29

    Python: How to execute more than 1 command over SSH without loggin in every command

HotTag

Archive