-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-copy.sh
executable file
·36 lines (29 loc) · 1012 Bytes
/
ssh-copy.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
#!/bin/bash
: '
Script Name: ssh-copy
Author: Ahmad Shoaib Joya
Date: 26.06.2023
Version: v1.0.0
Descriptioin: This script is for Copying the SSH Key to the remote Hosts which have same username and password.
'
# The Script requires your inventory file as input. Your inventory file must have IPs of remote hosts.
# You need to change the key_path variable to your ssh key path.
key_path="/home/ahmadshoaibjoya/.ssh/id_ed25519.pub"
inventory=$1
if [[ ! -f $inventory ]]
then
echo "You did assign the Inventory file as Input."
exit
fi
echo "The $key_path key will be copied to the hosts."
echo "Enter Hosts Username."
read -p "Username: " username
echo "Enter Hosts Password."
read -s -p "Password: " password
echo "Your Inventory file: $inventory"
hosts=$(awk '/^([0-9]{1,3}\.){3}[0-9]{1,3}/ { print $1 }' $inventory)
while read ip
do
echo -e "\033[32m========>\033[0m" "\033[1;31m$ip\033[0m"
sshpass -p $password ssh-copy-id -o StrictHostKeyChecking=no -i $key_path $username@$ip
done <<< $hosts