以其他用户身份运行Shell命令或更改Apache用户? [英] Run a shell command as another user or change Apache's user?

查看:181
本文介绍了以其他用户身份运行Shell命令或更改Apache用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图弄清楚整天如何做.

简短版本:我必须使用php shell_exec函数来管理某些虚拟机,但到目前为止,我无法做到这一点,因为apache由用户www-data和virtualbox由用户vboxuser运行

到目前为止,我已经想到了3种可能的解决方案: 1.-在我的vboxuser上创建一个脚本,我可以从php调用该脚本来管理虚拟机. 2.-将apache用户从www-data更改为vboxuser,这样我就可以通过php管理虚拟机 3.-重新安装VirtualBox,这次使用www-data作为我的用户.

我不确定其中任何一个是否可以使用,我不太确定哪种方法是最佳解决方案.有什么建议/想法吗?

谢谢.

现在更详细的版本:

我有一台运行Ubuntu 10.04.2的远程服务器,在该服务器上,我已经设置了VirtualBox,因此我可以运行WinXP的多个实例来执行不同的任务.

一切都已设置好,我可以通过SSH管理虚拟机.如果我想以与创建它们的用户不同的用户身份运行它们(到目前为止,该用户仅用于创建虚拟机),我必须执行sudo -u vboxuser.

现在,我需要创建一个PHP脚本来管理这些虚拟机(我了解phpVirtualBox,但这不是我所需要的).如果我尝试使用php中的shell_exec()运行虚拟机,我将一无所获(而且我已经测试过shell_exec在我的服务器上可以正常工作).

解决方案

您可以配置sudo以允许www-data以vboxuser的身份执行命令 使用sudo visudo将行添加到/etc/sudoers之类的

www-data(ALL)=(vboxuser)/usr/bin/vboxmanage

查看man sudoers以获取更多信息

I've been trying to figure out how to do this the whole day.

The short version: I have to manage some virtual machines using php shell_exec function, so far I cant do this because apache is run by the user www-data and virtualbox by the user vboxuser

From what I've read so far, I've thought of 3 possible solutions: 1.- Create a script on my vboxuser that I can call from php to manage the Virtual Machines. 2.- Change the apache user from www-data to vboxuser so I can manage the Virtual Machines through php 3.- Reinstall VirtualBox, this time using www-data as my user.

I'm not sure if any of these will work and I'm not too sure of which would be the best solution. Any suggestions/ideas?

Thanks in advance.

Now the longer more detailed version:

I have a remote server running Ubuntu 10.04.2, in that server I have set up VirtualBox so I can run several instances of WinXP to perform different tasks.

Everything is setup and I can manage the virtual machines through SSH. If I want to run them as a different user than the one that created them (a user that so far only has been used to create the Virtual Machines) I have to do sudo -u vboxuser.

Now, I need to create a PHP script to manage these virtual machines (I know about phpVirtualBox, but it's not what I need). If I try to run the virtual machines using shell_exec() from php, I get no answer at all (And I have tested that shell_exec is working on my server).

解决方案

you can configure sudo to allow www-data to execute commands as vboxuser use sudo visudo to add a line to /etc/sudoers like

www-data (ALL) = (vboxuser) /usr/bin/vboxmanage

check man sudoers for more information

这篇关于以其他用户身份运行Shell命令或更改Apache用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆