开发者

what is the best way to run shell script (with root privilege) via php?

I've made a simple bash script for 开发者_如何学Pythonserver admininstration and I cannot figure how can I run it in safely inside a php page: I'd like to create a php admininstration page but I obviously don't want to hard-code root password anyware. Let's make an example (this is a foo script, of course)

#!/bin/bash
touch /$1

this simple/stupid script will not work if the user who run it as no writing permission on /.

Actually the script add apache virtualhosts, ftp users and so on... any ideas?

thanks


Use

sudo /path/to/executable/file

and set up sudo so it can execute the following command for the current user as a root.

http://www.sudo.ws/sudo/sudoers.man.html - here is the sudoers manual, the configuration file, that you have to modify.

zerkms ALL = (ALL) NOPASSWD: /sbin/iptables -L FORWARD -n -v -x

This is example from my /etc/sudoers. Here I allowed to run command /sbin/iptables -L FORWARD -n -v -x as root without asking a password for user zerkms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜