LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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



Reply
 
Search this Thread
Old 08-17-2011, 07:06 AM   #1
carlosOFF
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Rep: Reputation: 0
Question 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
 
Old 08-17-2011, 08:22 AM   #2
salemeni
Member
 
Registered: Aug 2011
Posts: 64

Rep: Reputation: Disabled
Quote:
Originally Posted by carlosOFF View Post
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

Last edited by salemeni; 12-06-2011 at 03:59 AM.
 
Old 08-22-2011, 07:41 AM   #3
carlosOFF
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Sorry but I didn't understand the script...
 
Old 08-22-2011, 07:46 AM   #4
salemeni
Member
 
Registered: Aug 2011
Posts: 64

Rep: Reputation: Disabled
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

Last edited by salemeni; 08-22-2011 at 08:21 AM.
 
Old 08-22-2011, 08:25 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
You might find it easier to use http://linux.die.net/man/8/newusers
 
Old 08-24-2011, 11:36 AM   #6
mike-ocs
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Rep: Reputation: Disabled
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 12:00 PM. Reason: link to commercial site removed. No advertising allowed here.
 
  


Reply

Tags
create, script, user


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
create a directory at user home using shell script nagendrar Solaris / OpenSolaris 10 04-30-2010 06:30 AM
create user and database in the same time script asdasdqwe Linux - General 5 04-12-2010 06:03 PM
Create user accounts from shell script? maheshkodamati Linux - Newbie 1 02-26-2008 12:46 PM
HOW-TO? Create User, Set Password with script longtex Suse/Novell 13 10-02-2005 03:35 PM
Create user script kelper Linux - Software 1 06-24-2003 10:32 PM


All times are GMT -5. The time now is 04:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration