• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 487
  • Last Modified:

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
0
merlin152
Asked:
merlin152
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
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
 
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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now