Linux Scripting: Changing Passwords

Hello Everyone,

If you read my last question on this forum ("Linux Shell Scripting"), you will know my situation. However, now I need to change the passwords of 550 users using a shell script.

Again my usernames are in the form of user1 to user550. I've used the passwd command to change the first passwd manually. So the output was :-

passwd user1 [rtn]
Changing Password for user user1
New Unix Password: [password]
Retype new UNIX password: [password]
passwd: all authentication tokens updated successfully.

How on earth am I supposed to script that!!!??

merlin152
merlin152Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunnycoderCommented:
Hi merlin152,

#!/bin/bash
i=1
while [ $i -lt 551 ]
do
      passwd user$i
done

this will save you the trouble for typing in passwd commands
I guess you will have to type the passwords yourself
Cheers!
Sunny:o)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
liddlerCommented:
You need eXpect, a shell languagw which is good at dealing with passing parameters to other programs.
http://expect.nist.gov/
0
merlin152Author Commented:
What if for every user the passwords were the same? say the password was 'student' could that be inserted somewhere in the loop?

Does the passwd command allow you to pass the password as well as the username?
0
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

liddlerCommented:
AFAIK only if you use expect, other scripting languages can't pass the second occorance of the password
0
sunnycoderCommented:
yes you can add a password while adding a user using -p option, see the man page
-p passwd
              The encrypted password, as returned by crypt(3).  The default is to disable the account.
0
merlin152Author Commented:
Question:

How do you get the encrypted string of 'student'?
0
liddlerCommented:
just add a new user, set it's password as student, then look in /etc/passwd (or /etc/shadow if you are using shadowed passwords) will have the encrypted string in it  
0
mr_rabitCommented:
try and use chpasswd please read first the manual

with this command you can read out a textfile.

in this text file must be the user name and behind it the password.

so you can make a textfile run the command and ou are finisched
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Networking

From novice to tech pro — start learning today.