Good afternoon, there was a need to manage iptables from the nodejs application, as I understood iptables can only be called using sudo,

put pm2

sudo npm i pm2 -g --unsafe-perm 

sudo pm2 command did not appear, just run

 pm2 start app.js 

does not allow to execute sudo command from the application, tell me what else you need to do in order for the application to receive root rights

  • one
    I do not quite understand the necessity of launching from under the root, but I can definitely say that it is better to never launch from under the root. - Nikita Lyashenko

1 answer 1

I solved a similar task of password entry automation (Ubuntu):

  1. Install expect ( sudo apt-get install expect )
  2. Create superman.sh with the following content:

     #!/usr/bin/expect -f spawn sudo pm2 start app.js expect "assword:" send "СИМВОЛЫ_ПАРОЛЯ\r" interact 
  3. Take minimal precautions against password compromise