[英]what is the best way to run shell script (with root privilege) via php?
I've made a simple bash script for server 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. 我为服务器管理做了一个简单的bash脚本,但我想不出如何在php页面中安全地运行它:我想创建一个php admininstration页面,但是我显然不想硬编码root密码anyware。 Let's make an example (this is a foo script, of course)
让我们举个例子(当然,这是一个foo脚本)
#!/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? 实际上,该脚本添加了apache虚拟主机,ftp用户等...任何想法?
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. 并设置
sudo
以便它可以root用户身份为当前用户执行以下命令。
http://www.sudo.ws/sudo/sudoers.man.html - here is the sudoers manual, the configuration file, that you have to modify. http://www.sudo.ws/sudo/sudoers.man.html-这是您必须修改的sudoers手册(配置文件)。
zerkms ALL = (ALL) NOPASSWD: /sbin/iptables -L FORWARD -n -v -x
This is example from my /etc/sudoers
. 这是我的
/etc/sudoers
示例。 Here I allowed to run command /sbin/iptables -L FORWARD -n -v -x
as root
without asking a password for user zerkms
. 在这里,我允许以
root
身份运行命令/sbin/iptables -L FORWARD -n -v -x
,而无需询问用户zerkms
的密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.