Adding a user using php

Posted on 2003-03-18
Medium Priority
Last Modified: 2013-12-16

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?

Question by:choccarlm

Accepted Solution

jnbkze earned 400 total points
ID: 8159350
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.

Expert Comment

ID: 9076616
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Expert Comment

ID: 13688274

That was extremely rude and unprofessional.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will giveā€¦
Cron is one of the most popular and basic utilities found on Unix systems. Combined with other tools, cron makes it exceptionally easy to automate a broad range of tasks on your server.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question