Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
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
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
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
Last edited by colucix; 08-24-2011 at 11:00 AM.
Reason: link to commercial site removed. No advertising allowed here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.