问题描述
我正在尝试在Ubuntu服务器上从PHP运行非特权用户拥有的Shell脚本.权限问题使使用exec()
运行它不切实际,因为运行它的是www-data
.我在Google上进行了一些搜索,找到了对suExec的各种引用(似乎很难解决这么小的问题),设置suid位,以及Stackoverflow上的一种有趣的方法,其中涉及Python服务器监听发送的命令通过PHP.
I'm trying to run a shell script owned by a non-privileged user from PHP on an Ubuntu server. Issues with permissions make running it with exec()
impractical, as it's www-data
that's running it. I've googled a bit and found varius references to suExec (which seems too much of a hassle to get working for such a small problem), setting the suid bit, and an interesting approach here on Stackoverflow involving a Python server listening for commands sent by PHP.
无论如何,在所有这些解决方案中,我倾向于一种涉及设置suid位的方法,尝试了一下,但没有成功:chmod u+s script.sh
,而且我的Apache日志仍然显示权限错误,所以我知道脚本是不是以所有者身份运行,而是以www-data
身份运行.
Anyway, of all of these solutions, I lean towards the one involving setting the suid bit, tried it and it didn't work : chmod u+s script.sh
, and my Apache logs still show permission errors, so I know the script is not running as it's owner but as www-data
.
要使此功能正常工作,我该怎么做?有没有更简单的解决方案?
What do I have to do to get this working, and is there a simpler solution for this problem ?
推荐答案
看看sudo的手册页:sudo -u your_other_user
将让您以其他用户的身份执行命令.
Take a look at the man page for sudo: sudo -u your_other_user
will let you execute the command as the other user.
还使用man sudoers查找用户可以使用sudo执行哪些命令的选项.
Also use man sudoers to look for options on which user can execute what commands with sudo.
这篇关于以不同的(非root)用户身份从PHP运行shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!