node.js - Run linux command without password that need root permission -
i'm using node execute bash command on linux. need stop , start apache server. bash need type:
sudo service apache2 stop
and need insert password. change modify 'visudo' after modification not asking password when run node error
error: command failed: /bin/sh -c sudo systemctl status apache2.service sudo: no tty present , no askpass program specified
where problem? node code looks that
app.get('/statustest', function(req, res){ exec("sudo systemctl status apache2.service", function(err, stdout){ if(err) throw err; console.log(stdout); res.render('statustest'); }); })
you can try command automatic password input:
exec(`echo 'your_sudo_password' | sudo -s systemctl status apache2.service`, ...);
Comments
Post a Comment