Solved

Linux Scripting: Changing Passwords

Posted on 2003-10-24
8
451 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
  • 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now