Could not execute useradd command through PHP

February 15, 2011 at 23:02:19
Specs: Windows XP
I am uploading my PHP script to linux server from client windows server. In PHP script i am trying to execute Linux command USERADD, to create new FTP user.
This is the code -- shell_exec("useradd -d /home/".strtolower($_POST['username'])." -p ".crypt($_POST['password']));

But i am unable to create the user. Please help.

See More: Could not execute useradd command through PHP

Report •

February 15, 2011 at 23:34:51
You need the full path to useradd.

And you best run the $_POST variable through escapeshellarg, just in case...

Report •

February 15, 2011 at 23:57:58
I tried using this :

shell_exec("/usr/sbin/useradd -d /var/www/".escapeshellarg($_POST['username'])." -p ".crypt($_POST['password']));

but still the user is not creating..

Report •

February 16, 2011 at 00:57:48
Do you get any error messages? What user is running the PHP script? Unless the user has root privilegeson the Linux server the useradd command is bound to fail.

Report •

Related Solutions

February 16, 2011 at 01:17:06
Check the output of the command -

echo shell_exec(" ...

It's generally a bad idea to pass anything to the shell from a web script, and you should be very careful when doing so...

That being said - if you still need to run it as root, you can use the setuid bit on the file, something like:

chmod +s /path/to/useradd


Again, be careful doing this. Without the 'escapeshellarg' command added above, your server could be easily hacked...

Report •

February 16, 2011 at 01:21:11
I am not getting any error messages, even checked that log files, NO error.

I am running Apache WAMP server. Wat configurations i need to check???

Report •

February 16, 2011 at 01:23:42
I am logging in as root to the Linux server, which as all the privilages

Report •

Ask Question