Visit Our UNIX and Linux User Community


script to change password for all users


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to change password for all users
# 1  
Old 08-24-2009
script to change password for all users

We have a server where we have a number of user ids and we also have the list of old passwords in a CSV file.
Now we want to change the password of all the users and assign them a default password.Can we write a shell script to do that.
I am planning to read the user name and corresponding password from CSV file.But how to login to the server with the same user and change password
with passwd -r file command.
Once i type login the exported paramter values are lost.

Any suggestion or sample script will help.

thanks
Deepak
# 2  
Old 08-24-2009
with the --stdin option of the command 'passwd',you can do it easily as root
Code:
echo 'the old pass you read from csv file' | passwd --stdin user

post a sample of your csv file,i 'll try
# 3  
Old 08-24-2009
Code:
user_id,old_password,new_password
dkrout,P@55word,dk@11word
sdas,P@55word,sd@12word
bkpradhan,P@55word,bk@19word
pthn,P@55word,pt@11word
nsap,P@55word,ns@11word


This is a sample CSV file I am having.I want to change the password to new password.I want to make everythin automated so that after the script run is complete password should change for all users and automated mail will be sent to them.

---------- Post updated at 07:44 PM ---------- Previous update was at 07:17 PM ----------

Quote:
Originally Posted by dr46014
Code:
user_id,old_password,new_password
dkrout,P@55word,dk@11word
sdas,P@55word,sd@12word
bkpradhan,P@55word,bk@19word
pthn,P@55word,pt@11word
nsap,P@55word,ns@11word


This is a sample CSV file I am having.I want to change the password to new password.I want to make everythin automated so that after the script run is complete password should change for all users and automated mail will be sent to them.
one thing i forgot to mention..i am not the root user.I am an ordinary user who wants to change the password.It is same as loggin in to individaul user using their password and change it and send a mail.To avoid manual work i want to automate it.

Last edited by vgersh99; 08-24-2009 at 10:53 AM.. Reason: code tags, PLEASE!
# 4  
Old 08-24-2009
sorry,i don't know how if you can't access root,i just tried 'sudo',didn't work
i guess its for the security,you need to be root to change others password 'in script'
# 5  
Old 08-24-2009
can you frame the script assuming that i am the root user..
i will try to convenience SA team to implement it once the script is ready
# 6  
Old 08-24-2009
Code:
awk -F, 'NR!=1{system("echo "$3"|passwd --stdin "$1)}' yourCSVfile

and..about the mail,if you changed their passwords,how do they login and check mail without know the new password?hehe
# 7  
Old 08-24-2009
Quote:
Originally Posted by b33713
Code:
awk -F, 'NR!=1{system("echo "$3"|passwd --stdin "$1)}' yourCSVfile

and..about the mail,if you changed their passwords,how do they login and check mail without know the new password?hehe
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here

---------- Post updated at 10:13 PM ---------- Previous update was at 10:09 PM ----------

Quote:
Originally Posted by dr46014
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here
this is not working in my system ....

---------- Post updated at 10:26 PM ---------- Previous update was at 10:13 PM ----------

Quote:
Originally Posted by dr46014
we can add another column and have the corresponding mail ids ... not unix mail...and use mailx -s .... that is quite possible...i dont understand the use of system here

---------- Post updated at 10:13 PM ---------- Previous update was at 10:09 PM ----------



this is not working in my system ....
won't this ask for old password and confirmation password if i am running it from root..as i dont have that access its not working .....
will it work in Sun Solaris too ??

Previous Thread | Next Thread
Test Your Knowledge in Computers #840
Difficulty: Medium
Apache2 has supported WebSockets since 2013.
True or False?

10 More Discussions You Might Find Interesting

1. AIX

Change password for many users on an AIX server

Hi I want to change password for around 100 users on an aix server. I have the list of those 100 users with me. instead of doing # passwd username for all the 100 users one by one, can you please help with a script through which we can change the password for all the 100 users in a... (2 Replies)
Discussion started by: newtoaixos
2 Replies

2. Shell Programming and Scripting

Shell script for creating multiple users with password

for UserName in `cat users` ; do useradd -d /u02 -s /usr/libexec/openssh/sftp-server -G ftp-users $UserName ; PassWord=$( echo $( tr '' '' <<< ${UserName:0:1} )${UserName:1} ) ; echo "$PassWord@123" | passwd $UserName --stdin ; done can some one explain what the bold text do Please use... (5 Replies)
Discussion started by: James0806
5 Replies

3. Shell Programming and Scripting

Bulk NIS Users Password Change

Hi All, I am having Solaris 5.10 acting as NIS. How do i change multiple user password in NIS in a batch. I have predefined users with their passwords to be set: Example: user1 password1 user2 password2 Pls advise. (0 Replies)
Discussion started by: yogajwa
0 Replies

4. Solaris

Change password for users

I am on SunOS SolarisServer 5.11 11.1 i86pc i386 i86pc , I am trying to change password for a user,but I get the following message.I cannot find any google help on the matter.can anyone help? root@SolarisServer:~# passwd passwd: Changing password for stain Please try again Please try... (6 Replies)
Discussion started by: cbtshare
6 Replies

5. UNIX for Advanced & Expert Users

Update users password change time

Hello - Is this possible on Unix machines? Can we update user password change time? (6 Replies)
Discussion started by: manju--
6 Replies

6. Solaris

How to enforce all users to change their password

Hi All, How to enforce all users to change their password when they try to login. I am having Solaris 9 and 10. Even it would be much better if anyone can say to enforce all users to change their password next morning they login. Thanks in advance, Deepak (3 Replies)
Discussion started by: naw_deepak
3 Replies

7. Shell Programming and Scripting

Help- Change the password of users to common one

Hi all I have some 106 users of which i need to change the password of them to a common one. I dont know their paswword. But i need to reset them to a common one. How can i do this with a shell script? It would be a great help if some one can help to sort out this.:b::b: I know it can be... (0 Replies)
Discussion started by: Tuxidow
0 Replies

8. Shell Programming and Scripting

how to change root password using shell script with standard password

Hi Friends. I am new to scripting now i want to change the root password using the script with standard password. which is the easy scripting to learn for the beginner, Thanks in advance. (2 Replies)
Discussion started by: kurva
2 Replies

9. Shell Programming and Scripting

Modify users password via script?

Ok, first off, I'm working on a Vmware ESX server, which I guess is loosely based off of Red Hat 9. But I'm brand new to it (today), so be nice. I'm trying to write a useradd script that will create some users, generate a password, and set their password to this newly generated password. ... (2 Replies)
Discussion started by: paqman
2 Replies

10. Shell Programming and Scripting

How do I change users in a script???

Hi there, Does anyone know of a way I can become a different user in a script? I need to run a script as one user (not root), and change to another user half way through. It stops and asks me for the password, and I can't find a way to feed the password in through the script. Thanks (2 Replies)
Discussion started by: chorgan
2 Replies

Featured Tech Videos