Solved

Linux Scripting: Changing Passwords

Posted on 2003-10-24
8
473 Views
Last Modified: 2010-03-18
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
Comment
Question by:merlin152
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 62 total points
ID: 9612785
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
 
LVL 18

Expert Comment

by:liddler
ID: 9612853
You need eXpect, a shell languagw which is good at dealing with passing parameters to other programs.
http://expect.nist.gov/
0
 

Author Comment

by:merlin152
ID: 9613008
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
Independent Software Vendors: 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!

 
LVL 18

Expert Comment

by:liddler
ID: 9613021
AFAIK only if you use expect, other scripting languages can't pass the second occorance of the password
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9613061
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
 

Author Comment

by:merlin152
ID: 9613409
Question:

How do you get the encrypted string of 'student'?
0
 
LVL 18

Assisted Solution

by:liddler
liddler earned 63 total points
ID: 9614649
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
 
LVL 1

Expert Comment

by:mr_rabit
ID: 9633991
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question