Computing.Net > Forums > Programming > Add linux user through PHP

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Add linux user through PHP

Reply to Message Icon

Name: jbiss
Date: November 24, 2005 at 07:30:58 Pacific
OS: RedHat 9.0
CPU/Ram: 2x 600Mhz - 1Gig ECC
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: jdieter
Date: December 1, 2005 at 05:32:44 Pacific
Reply:

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.


0

Response Number 2
Name: jbiss
Date: December 3, 2005 at 13:25:08 Pacific
Reply:

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!!


0

Response Number 3
Name: jdieter
Date: December 3, 2005 at 22:52:01 Pacific
Reply:

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.


0

Response Number 4
Name: xavigonzalvo
Date: December 5, 2005 at 08:34:53 Pacific
Reply:

Look at this:

http://www.telecofreaks.net/modules.php?name=News&file=article&sid=9



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


reading from a file VBA Code?



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Add linux user through PHP

useradd command through php www.computing.net/answers/programming/useradd-command-through-php/18332.html

Howto Run www.computing.net/answers/programming/howto-run-/1135.html

Need help using PHP? PLEASE www.computing.net/answers/programming/need-help-using-php-please/9319.html