Question : Adding a user using php

Hi,

I need to be able to add users on my system through php scripts but I'm having some problems. Currently, my web sign up page writes the commands to a file, and then a cron job executes this file every few hours and clears it.

I.E Whenever someone signs up, the php page will append the follwing 2 lines to a file:

/usr/bin/ssh my.user.server.com -l root /usr/sbin/useradd -s /bin/false -d /var/username username
/usr/bin/ssh my.user.server.com -l root /bin/echo "password" | /usr/bin/ssh my.user.server.com -l root /usr/bin/passwd --stdin username

Then every 2 hours, a cron job will execute this file and the users get added.

IS there any way of getting php to add a user straight away? Whenever I try to do it using the exec or passthru command, I get the following error in the apache error log:

useradd: unable to lock password file

Whats the easiest way of adding users on the fly?

Thanks

Answer : Adding a user using php

The reason you're getting the error "Unable to lock file" is that you're running apache as a user other than root. Only the root user may use the useradd command.

You can do the method you want to do with the exec command. Bear in mind there are some security issues with doing it this way though.

First log onto the server where the useradd command gets run. and do this " chmod a+s /path/to/useradd"

Then you should be able to do you exec call again and it should work.

Again - I advise extreme caution with this because it will allow any person who has been able to access your php page to add a user account for himself.
Random Solutions  
 
programming4us programming4us