?
Solved

Adding a user using php

Posted on 2003-03-18
3
Medium Priority
?
256 Views
Last Modified: 2013-12-16
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
0
Comment
Question by:choccarlm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
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.
0
 

Expert Comment

by:CleanupPing
ID: 9076616
choccarlm:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 1

Expert Comment

by:jeffparis
ID: 13688274
CleanupPing

That was extremely rude and unprofessional.
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

764 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