Solved

Linux Scripting: Changing Passwords

Posted on 2003-10-24
8
461 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Samba Security Improvement for Writable Directories 8 75
Open BDS Pf 3 52
Proxy with authentication for internet access 5 121
High Bandwidth Usage 6 75
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

808 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