Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using shell_exec or exec as a different unix user?

Tags:

php

unix

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

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.

like image 989
MarcoT Avatar asked May 06 '26 11:05

MarcoT


1 Answers

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.

i want to execute commands as the git user

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.

like image 176
webbiedave Avatar answered May 08 '26 00:05

webbiedave