Changing user password in multiple servers

#!/bin/bash

Author: Rajesh

Version: 1.1

# Make sure that you have created a file with servers list in it. Hostname or ip. One name or ip in each line. The script will ask you to enter the filename as it is.

echo "Enter the username for which you want to change the password \n"

read USER

sleep 2

echo "Enter the password that you would like to set for $USER \n"

read PASSWORD

sleep2

echo "Enter the file name that contains a list of servers. Ex: servers.txt, host_list.txt OR WHATEVER YOU HAVE NAMED IT \n"

read FILE

sleep 2

echo "Enter the path of the directory where the $FILE is present. Ex: /root, /tmp OR WHEREVER YOU HAVE PLACED IT"

read PATH

sleep 2

for HOST in $(cat $PATH/$FILE)

do

ssh root@$HOST  "echo -e '$PASSWORD\n$PASSWORD' | passwd $USER"

done


 

Leave a Reply