LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Add user problem (https://www.linuxquestions.org/questions/linux-software-2/add-user-problem-97863/)

Swift&Smart 09-28-2003 11:26 AM

Add user problem
 
What's up!Everyone. :D

My question is that how can I add a user and set his/her password in one command line on Linux.I've tried -p option but it ain't work.Is that password being encrypted??

Any help is appreciated. ;)

iceman47 09-28-2003 11:47 AM

Code:

adduser <name>; echo "<passwd>" | passwd <name> --stdin

Swift&Smart 09-29-2003 10:34 AM

Stupid...
 
Thanks for your reply iceman47.However,how stupid that I am!I don't understand your code.Would you mind telling me in an example?

Quote:

e.g. useradd blah blah blah -p my_password
Thanks. :D

coolamit78 09-29-2003 11:14 AM

i think this should work...

log in as root

suppose u wanna add a user called 'swift'..then issue the following command..

useradd swift; passwd swift

then it will prompt u twice for the password....

Swift&Smart 09-29-2003 11:29 AM

Thanks,coolamit78.However,I intended to do it via PHP script with exec() function.So,I want to do this in "one" command line without any further prompt.

Thanks for all you guys every efforts to help me out.:D

coolamit78 09-29-2003 11:52 AM

well....the -p option that is used with the useradd command needs an encrypted password, so u cant provide this password directly as it wouldnt be possible for u to perform the encryption manually. Therefore, u have to achieve this in some other indirect way. I am not in a position to suggest u anything right now....I'll sure, post a reply later after I try to do that with a single command..

good luck

iceman47 09-29-2003 12:43 PM

Re: Stupid...
 
Quote:

Originally posted by Swift&Smart
Thanks for your reply iceman47.However,how stupid that I am!I don't understand your code.Would you mind telling me in an example?
Sure, suppose that iceman is your name and you want your password to be letmein, do this:

Code:

adduser iceman; echo "letmein" | passwd iceman --stdin

Swift&Smart 09-29-2003 07:26 PM

It worksssssssssssss!!!!!!
 
Wow,thanks a lot iceman47.It works!!!Thank you so much! ;)

iamthewind 09-29-2003 09:05 PM

I did £¡ And it works £¡ ¹ş¹ş thanks everyone£¡

coolamit78 09-30-2003 03:37 AM

adduser iceman; echo "letmein" | passwd iceman --stdin

Ok....i agree that this command rocks.....but I havent understood it entirely...

Now here, the output of echo is piped to the passwd command (this is what --stdin is actually doing....it takes the input as if it was coming through the standard input)

Now my question is....whenever we give the command 'passwd', it prompts us 2 times to enter the password. But here, the piped output of echo is just one out of the total 2 times....then how come it does not ask for password rentry??

pls clarify..

thanks

iceman47 09-30-2003 06:30 AM

Quote:

Originally posted by coolamit78

Now my question is....whenever we give the command 'passwd', it prompts us 2 times to enter the password. But here, the piped output of echo is just one out of the total 2 times....then how come it does not ask for password rentry??

Because that's just what the --stdin does, it takes whatever is been offered on that moment and uses it as the password, no verification needed.

Swift&Smart 10-11-2003 12:29 AM

New problem....
 
It's me again.. :D Anyway,back to the problem.

Indeed,this script works fine when I execute it via command line (PHP).But what I exactly wanna do is when someone signs up,it will automatically add a user on my server.However,this script can only be executed by ROOT.Indeed,it's somehow very dangerous...:rolleyes: My question is,how can I run this script in a more secure way/how to run it as ROOT?

Many thanks. ;)

Shade 10-11-2003 08:23 AM

dude... NOT SAFE.

You're basically allowing *everyone* user-level access to the system... How do you mean, "when someone signs up"... Signs up how?

While you rethink that, read up on the setuid utility for executing the script.

Code:

man setuid
-Shade

Swift&Smart 10-11-2003 11:01 AM

What I mean...
 
dude,thanks for your reply. :)

What I mean is that when someone signs up as my website's member,I want my system automatically adds them to my server.So I don't have to do it on my own everytime.

Do you know what I mean?Thanks. :D

mossy 10-11-2003 11:32 AM

I take it you want to let people register a uid and password for your site -


All times are GMT -5. The time now is 10:19 PM.