Babajaga
Babajaga

Reputation: 87

Execute a script as another user

I have 6 scripts that I execute with PHP, unfortunately, I have to execute it as my default user. I tried to execute it with PHP only but it doesn't work.

Do you know how to do this without a big security breach ?

Thank you :)

Upvotes: 1

Views: 5350

Answers (2)

hashier
hashier

Reputation: 4750

You can use sudo to run a program as a different user.

Here is an example. I am root from the beginning (which you can see since id tells it) and execute the program id as the user hashier.

$
$ id
uid=0(root)
$ sudo -u hashier id
uid=501(hashier)
$

Upvotes: 0

Hless
Hless

Reputation: 3316

You can use php as a command line utility by typing php /path/to/script.php

The PHP script will be excecuted by the user you are logged in to.

Upvotes: 1

Related Questions