I have a script script.py which I'm able to execute via CGI by navigating to mydomain.com/runscript .
The script however makes a subprocess call to echo "mysqldump ..." | sudo -i and sudo python using os.system(COMMAND) . When I attempt to run the script via the weblink, I get this error in /var/log/apache2/error.log :
[Fri Jul 29 16:52:42.515223 2016] [cgi:error] [pid 3013] [client ##.###.##.##:#####] AH01215: sudo: no tty present and no askpass program specified
This is because CGI runs as user www-data , which doesn't have sudo permission.
I've tried adding this to my sudoers file:
%www-data ALL = (root) NOPASSWD: /var/www/html/scripts/script.py
however the errors persist. Why are the subprocess calls not receiving root access, and how can I give it to them and ONLY them? Thank you!
您可以通过以下方式将密码传递给sudo命令:
echo <your password> | sudo -S <your command>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.