Operating System - Linux
1820890 Members
3887 Online
109628 Solutions
New Discussion юеВ

Need specifics on how to use "useradd -p" to add user and set pword

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

Need specifics on how to use "useradd -p" to add user and set pword

I need to add hundreds of users to a Red Hat ES 3.0 system. I want to create a script with a bunch of useradd lines in it. Everything's fine except the -p option that I need to set an initial password.

This option uses the "crypt" function, yet the man page on useradd and crypt doesn't give specific details on how to use it.

Can anyone give me an example useradd line including how to use the -p command?
6 REPLIES 6
RAC_1
Honored Contributor

Re: Need specifics on how to use "useradd -p" to add user and set pword

With useradd command add the users. then you can use chpasswd command to set the passwords for them. chpasswd command takes the files as an argument. The will have usser name and a password as follows.

user1 teryy@1
user2 onegoat1

Anil
There is no substitute to HARDWORK
Debbie Fleith
Regular Advisor

Re: Need specifics on how to use "useradd -p" to add user and set pword

Even Red Hat themselves didn't tell me about the chpasswd command. Thanks so much.

But, can you please give me a bit more detail on how to use it? The man page is not clear.

If I want to create a script to assign a user login "test" with a password of "pword", login of "test2" password "pword2", (for hundreds of accounts) what should the script have in it?

Do I use just a bunch of lines like this?
chpasswd test:pword
chpasswd test2:pword2

, and then run the script from a prompt?

Stuart Browne
Honored Contributor
Solution

Re: Need specifics on how to use "useradd -p" to add user and set pword

No, it works like this:

echo username:password | chpasswd

You can do them individually (like above), or you can put them all in a file, and then:

chpasswd < file

do change them en-masse.

There used to be a small utility to generate an encrypted password to the console included, but I couldn't find it on my system, so this is probably the easiest way.
One long-haired git at your service...
Oguz Kutlu  Asik
Honored Contributor

Re: Need specifics on how to use "useradd -p" to add user and set pword

There was a "newusers" utility for Redhat. man newusers.
What's right is right, whether or not God exists
Gopi Sekar
Honored Contributor

Re: Need specifics on how to use "useradd -p" to add user and set pword


another method to call it from script is to use passwd utility's --stdin functionality

echo password | /usr/bin/passwd username --stdin

it will set the 'password' as password for user 'username'

remember only root can do this.

Hope this helps,
Gopi
Never Never Never Giveup
Debbie Fleith
Regular Advisor

Re: Need specifics on how to use "useradd -p" to add user and set pword

closed