LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script to create user (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-create-user-897811/)

carlosOFF 08-17-2011 06:06 AM

Script to create user
 
Good morning everybody,


I'm trying to create a script to create and configure users, so far, i can create, but i'm having one problems:

1) about the password, i discovered that when you pass it in useradd is the encrypted password.
So what i want is to use passwd in my script, how i can put to be automatic?

Thanks!

Carlos

salemeni 08-17-2011 07:22 AM

Quote:

Originally Posted by carlosOFF (Post 4445410)
Good morning everybody,


I'm trying to create a script to create and configure users, so far, i can create, but i'm having one problems:

1) about the password, i discovered that when you pass it in useradd is the encrypted password.
So what i want is to use passwd in my script, how i can put to be automatic?

Thanks!

Carlos

to use passwd in your script try to use expect command

http://bash.cyberciti.biz/security/e...-login-script/

generics array

carlosOFF 08-22-2011 06:41 AM

Sorry but I didn't understand the script...

salemeni 08-22-2011 06:46 AM

Expect is a program that "talks" to other interactive programs according to a script. Following the script, Expect knows what can be expected from a program and what the correct response should be. An interpreted language provides branching and high-level control structures to direct the dialogue. In addition, the user can take control and interact directly when desired, afterward returning control to the script.
http://linux.die.net/man/1/expect
Samples
http://www.aixmind.com/?p=1979

chrism01 08-22-2011 07:25 PM

You might find it easier to use http://linux.die.net/man/8/newusers

mike-ocs 08-24-2011 10:36 AM

An easy way to do this in a script is to echo something into the passwd command. If you do, you'll need to add the --stdin option for passwd. Depending on the password that you set, you may want to force your new users to change their passwords the first time they log in. This can be accomplished with chage -d0. Here's a simple bash for loop that demonstrates this. It will add four users, set their passwords to be the same thing as their usernames, and force them to change their password the first time they log in.

for NAME in mike brian chris susan; do useradd $NAME; echo $NAME | passwd --stdin $NAME; chage -d0 $NAME; done

Mike


All times are GMT -5. The time now is 06:58 PM.