[英]PHP: Run Shell Script as root user
I'm trying to run a script as root user. 我正在尝试以root用户身份运行脚本。 here is my code
这是我的代码
echo shell_exec("sudo bash.sh 2>&1");
It's giving error 出错了
sudo: no tty present and no askpass program specified
www-data is not in the sudoers file. This incident will be reported.
I've followed these methods as well but end up with no permission
error 我也遵循了这些方法,但是最终
no permission
错误
There are a couple of issues you might encounter: 您可能会遇到几个问题:
visudoers
command) visudoers
命令检查) $PATH
variable does not include the path to the sudo command $PATH
变量不包含sudo命令的路径 sudo
might require a password. sudo
可能需要密码。 Either change the sudoers file, adding NOPASSWORD
, which would be hugely unsafe. NOPASSWORD
,这将是非常不安全的。 Or you have to use pipes ( proc_open
), and pass the password through the stdin pipe proc_open
),并通过stdin管道传递密码 I've managed to find a way to do so, but after some help from people on this site: 我设法找到了一种方法,但是在此站点上的人提供了一些帮助之后:
load .profile with proc_open() 用proc_open()加载.profile
proc_open interaction proc_open互动
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.