使用 shell_exec 或 exec 作为不同的 unix 用户? [英] Using shell_exec or exec as a different unix user?

查看:29
本文介绍了使用 shell_exec 或 exec 作为不同的 unix 用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在运行 shell_exec 或 exec 时以不同的用户身份登录 PHP 吗?

Can i make PHP login as a different user while running shell_exec or exec?

我不希望它使用 www-data 用户,因为我想以 git 用户身份执行命令以便在当前机器上创建存储库.

I don't want it to use the www-data user, since i want to execute commands as the git user in order to create repos in the current machine.

推荐答案

我可以在运行 shell_exec 时以不同的用户身份登录 PHP 吗?执行?

Can i make PHP login as a different user while running shell_exec or exec?

这是一个有风险的选择,它会在您的服务器中造成严重的安全漏洞.应该避免.

This is a risky option and it can create a serious security hole in your server. It should be avoided.

我想以 git 用户身份执行命令

i want to execute commands as the git user

我建议您的 Web 应用程序将有关需要创建的新存储库的信息写入数据库表.然后在以 git 用户身份运行的服务器上有一个持续运行的进程(或通过 cron 调用的进程).该过程可以定期检查该资源并创建存储库.这样,您的 Web 服务器不会进行用户切换,您仍然可以安全地创建新的存储库.

I would suggest that your web app writes to a database table the information about the new repo that needs to be created. Then have a constant running process (or one invoked via cron) on the server that runs as the git user. That process can check that resource periodically and create the repo. That way, your web server doesn't user-switch and you can still create the new repo safely.

这篇关于使用 shell_exec 或 exec 作为不同的 unix 用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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