简体   繁体   English

通过PHP的shell_exec()从网页执行bash脚本,这需要另一个用户的权限吗?

[英]Executing a bash script from a web page via PHP's shell_exec(), which requires another user's perms?

I have a couple of bash scripts on a Centos box which I use to do basic server admin stuff like restart services, etc. I run these as a standard user who is also the scripts' owner. 我在Centos机器上有几个bash脚本,用于执行基本的服务器管理工​​作,例如重启服务等。我以标准用户的身份运行这些脚本,这些用户也是脚本的所有者。

I tried to run these using shell_exec() in PHP, with the apache user, but it simply doesn't work - I'm guessing it doesn't have enough permissions (even with 775 and being in the correct group!) to run everything I want it to. 我试图用Apache用户在PHP中使用shell_exec()运行这些程序,但是它根本行不通-我猜它没有足够的权限(即使使用775并且在正确的组中!)也无法运行我想要的一切。

I've tried editing the sudoers file giving apache permission to run the script calls but it still doesn't work and has no error messages that I can see. 我尝试编辑sudoers文件,以授予apache权限来运行脚本调用,但是它仍然无法正常工作,并且没有错误消息。

Any thoughts? 有什么想法吗? How can one trigger a script from a web page which requires a different user to run? 如何才能从需要另一用户运行的网页上触发脚本?

Make sure safe mode is off. 确保安全模式已关闭。 Also verify the user is the one you expect: 还要验证用户是否是您期望的用户:

<?php echo exec('whoami'); ?>
  1. check under which user is running apache ( for debian it is www-data) 检查哪个用户正在运行apache(对于debian,它是www-data)
  2. add www-data in sudoers list with permission to execute files that you like 在sudoers列表中添加www-data,并有权执行您喜欢的文件
  3. check which shell has www-data user in /etc/passwd (you will need to give valid shell) 检查哪个外壳在/ etc / passwd中具有www-data用户(您将需要提供有效的外壳)
  4. run script with /bin/bash -x (it will output for sure) 使用/ bin / bash -x运行脚本(肯定会输出)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM