-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsshall.sh
executable file
·51 lines (44 loc) · 1.54 KB
/
sshall.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
#!/bin/bash
node=(master slave1 slave2 slave3 slave4 slave5 slave6) # hostname for each node
username=hadoop # username to be interconnected
homename=$username # home dir, i.e. home/zhangyang
if [ "$username" = "root" ];
then
homename=root
else
homename=home/$username
fi
for((i=0; i<${#node[*]}; i++))
do
ssh $username@${node[i]} 'ssh-keygen -t rsa -f /'$homename'/.ssh/id_rsa'
done
#cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
echo "batch authorized_keys created..."
echo "start scp..."
#scp node003:/$homename/.ssh/authorized_keys /$homename/.ssh/node003.key
for((i=0; i<${#node[*]}; i++))
do
scp $username@${node[i]}:/$homename/.ssh/id_rsa.pub /$homename/.ssh/${node[i]}.key
echo "scp from ${node[i]} finished..."
done
echo "append key to authorized_keys..."
for((i=0; i<${#node[*]}; i++))
do
cat /$homename/.ssh/${node[i]}.key >> /$homename/.ssh/authorized_keys
echo "append ${node[i]}.key finished..."
done
cat /$homename/.ssh/authorized_keys | awk '!a[$2]++' > /tmp/authorized_keys
mv /tmp/authorized_keys /$homename/.ssh/authorized_keys
echo "append all key finished..."
loop=${#node[*]}
let subloop=loop-1
echo "starting scp complete authorized_keys to ${node[1]}~${node[subloop]}"
for((i=1; i<${#node[*]}; i++))
do
scp /$homename/.ssh/authorized_keys ${node[i]}:/$homename/.ssh/authorized_keys
echo "scp to ${node[i]} finished..."
done
echo "scp all nodes finished..."
# delete intermediate files
rm -rf /$homename/.ssh/*.key
echo "all configuration finished..."