-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathusercreation.sh
55 lines (54 loc) · 2.4 KB
/
usercreation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
######################################################################################
# #
# Script Created and Modified by Bijith Nair | bijithnair@hitachiconsulting.com #
# #
######################################################################################
echo "User Management Automation Tool :"
echo "Choose any of the option to proceed :"
echo "1. Create a password free authetication for single server"
echo "2. Create a password free authetication for multiple servers"
echo "3. Reset the password<use this option when you want to perform it for multiple servers>"
echo "4. Enter the command which you would like to execute it on multiple servers"
echo "5. Remove RSA key from the jump server"
echo -n "Select your choice [1 | 2 | 3 | 4 |or 5]?"
read version
if [ $version = 1 ]
then
echo "enter the ip of the server"
read -p "IP Address --:" IP && ssh-copy-id root@$IP
echo "Done...Go ahead and test it"
elif [ $version = 2 ]
then
echo " enter the location of the server's list"
read -p "Location --: " location
for host in $(cat $location); do ssh-copy-id $host; done
echo "Done...Go ahead and test it"
elif [ $version = 3 ]
then
echo "You are logged into : $(hostname) : $(date)"
echo "Please fill out the details correctly"
read -p "Enter username --: " username
read -s -p "Enter password --: " password
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
cat /tmp/Automated/SERVER_LIST.txt | while read a b
do
ssh -n $a "hostname; /usr/sbin/usermod -p $pass $username"
done
elif [ $version = 4 ]
then
echo "enter the command which you want to execute on multiple servers"
read -p "Command --:" command
#for host in $(cat $location); do ssh "$host" "$command" >"output.$host"; done
#for i in `cat /tmp/Automated/SERVER_LIST.txt`; do ssh $i 'echo -e "echo "==Hostname==" \n$(hostname)" $command; echo "==================""'; done
clear
for i in `cat /tmp/Automated/SERVER_LIST.txt`; do ssh $i 'echo -e ""Hostname:" $(printf "\e[4m%s\e[0m\n" $(hostname))" "\n$(echo "==Output==")"'; $command; echo "======================"; done
elif [ $version = 5 ]
then
echo "Enter the ip of the server"
read -p "IP Address --: " IP
ssh-keygen -R $IP
echo "Successfully removed the RSA keys!!!"
else
echo "Please choose from the give options only"
fi