0

How to change password of multiple users at a single command

I wants to changed the passwd of 3 Users at the same time. I have used the Following command

#passwd user1 user2 user3

Ended up facing the Following error

passwd: Only one user name may be specified.

How it can be done?

charmi
asked Apr 22, 2019
edited
1 Answer
1

Unfortunately This can't be Done in the above way.

But There is nothing known as "Cant" in linux You Just need a Custom Script With a userlist in sepearte File to change the password. Once you run the Script you can just enter password manually once by one. Most fastest Way posisble.

The below command will list the users who’s having /home directory and redirect the output to userlist.txt file.

 # cat /etc/passwd | grep "/home" | cut -d":" -f1 > user-list.txt

List out the users using cat command. Remove the username Which you don't wish to change the password.

Create a following shell script to achieve this.

#vi passwordchange.sh

#!/bin/sh
for user in `more userlist.txt`
do
echo "$user@123" | passwd --stdin "$user"
chage -d 0 $user
done

Set an executable permission to passwordchange.sh file.

Finally run the script to achieve this.

View More
linuxhelp
answered Apr 22, 2019
Your Answer
||||
x
 
100:0