3 Shell Scripts Change Multiple Users Password Single Go
Hi friends, I am going to show you a quick solution to reset multiple users password on single go or single shell script. Here i am sharing 3 shell scripts change multiple users password.
Shell scripts Change Multiple users password
Note: This scripts must be run by root user
#!/bin/bash for i in `cat /tmp/users` do echo $i echo "'Password@123'" | passwd --stdin "$i" done
Script 1 Explanation
In this script i have used for loop to assign list of users to $i variable and called variable. Create file /tmp/users and add user names one per line
[root@server]# sh users.sh Changing password for user aravi. passwd: all authentication tokens updated successfully.
#!/bin/bash for i in `cat /tmp/userlist`; do echo -e "NewPassword\nNewPassword" | passwd $i done
above script also same as method 1 but this time password is called two times separated by new line
Method 3 Change Users password
In this script we are not providing any user names in separate list we are directly taking user list from /etc/passwd file and change all the users password single go
while IFS=: read u x nn rest; do if [ $nn -ge 1000 ]; then echo 'StrongPassw0rd!' | passwd --stdin $u; fi done < /etc/passwd
Changing password for user nfsnobody. passwd: all authentication tokens updated successfully. Changing password for user aravi. passwd: all authentication tokens updated successfully.
loop in used along with while loop IFS – Internal Field Separator will separate passwd file records using : (Colon) as separator and assign there values to u x nn and remaining
this one liner is going to change users password which UID’s more than 1000 by calling user names and passing input password
if you want to change only few users password write the users list in file and redirect its input to this single liner script
That’s about changing multiple users passwords in single go. I hope this script is useful for you.
Thanks for your wonderful Support and Encouragement