Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to make a php script/form that will add users to a linux system over the internet. I'm using php as a scripting language, but can't find out the commands to use. I've tryied the exec( ... ) command but it doenst work. IF anyone could tell me what command to use to run the linux commands from the php script to the system, please let me know. I'm looking at exec( useradd $username) but this returns an error.

The most likely reason exec() doesn't work is that PHP is probably running under the "apache" username, and only root is allowed to add users.
As for fixing the problem, the easy (but incredibly insecure) option is to run php as suid root (you'll have to check the docs for that).
The other option is to write a small suid root script for adding users that is r-x by group apache and --- for everyone else.

Thanks for the info. However, I really dont want to set php as root, and I'm not to sure how to write a script to do it. I was wondering if its possible to do it inside the php script. Here is a small sample of the code, if you need more, just let me know.
$user = $_POST[user_name];
$password = $_POST[password];
passthru ("su -");
passthru ("root's password");
passthru ("useradd $user -p $password" );It doesnt work now, but I'm wondering if I can do something like this or if I'm getting close to making it work. I read that it's better to use passthru then the exec command.
Thanx again for the info!!

A couple of things to think about...
1) When using passthru, you must use the entire path of the executable (i.e. passthru("/sbin/useradd $user -p $password").
2) You might want to look into using sudo rather than su. I'm not convinced that the first and second passthru statements will really work together, though you can, of course, give it a try.

![]() |
reading from a file
|
VBA Code?
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |