-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathfixssh.sh
executable file
·81 lines (42 loc) · 2.31 KB
/
fixssh.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
FIXHOSTS=$@
ROOTKEYS=[]
GRIDKEYS=[]
ORACLEKEYS=[]
MYLOOP=0
for MYHOST in ${FIXHOSTS?}; do
docker exec ${MYHOST?} sh -c "touch /etc/ssh/ssh_known_hosts && chmod 644 /etc/ssh/ssh_known_hosts" || \
echo "Unable to generate ssh_known_hosts on ${MYHOST}"
docker exec ${MYHOST?} sh -c "ssh-keyscan -t ecdsa ${FIXHOSTS?} >> /etc/ssh/ssh_known_hosts 2> /dev/null" || \
echo "Unable to scan for known_hosts keys on ${MYHOST}"
docker exec ${MYHOST?} sh -c "[[ -f ~/.ssh/id_rsa ]] || ssh-keygen -q -N '' -f ~/.ssh/id_rsa" || \
echo "Unable to generate root SSH key on ${MYHOST}"
ROOTKEYS[${MYLOOP?}]=$(docker exec ${MYHOST?} sh -c "cat ~/.ssh/id_rsa.pub") || \
echo "Unable to get root key from ${MYHOST}"
docker exec --user grid ${MYHOST?} sh -c "[[ -f ~/.ssh/id_rsa ]] || ssh-keygen -q -N '' -f ~/.ssh/id_rsa" || \
echo "Unable to generate grid SSH key on ${MYHOST}"
GRIDKEYS[${MYLOOP?}]=$(docker exec --user grid ${MYHOST?} sh -c "cat ~/.ssh/id_rsa.pub") || \
echo "Unable to get grid key from ${MYHOST}"
docker exec --user oracle ${MYHOST?} sh -c "[[ -f ~/.ssh/id_rsa ]] || ssh-keygen -q -N '' -f ~/.ssh/id_rsa" || \
echo "Unable to generate oracle SSH key on ${MYHOST}"
ORACLEKEYS[${MYLOOP?}]=$(docker exec --user oracle ${MYHOST?} sh -c "cat ~/.ssh/id_rsa.pub") || \
echo "Unable to get oracle key from ${MYHOST}"
let MYLOOP++
done
for MYHOST in ${FIXHOSTS?}; do
for MYKEY in $(seq 1 ${#ROOTKEYS[@]}); do
let MYKEY--
docker exec ${MYHOST?} sh -c "echo ${ROOTKEYS[${MYKEY?}]} >> ~/.ssh/authorized_keys"
done || echo "Unable to add root public SSH keys on ${MYHOST}"
for MYKEY in $(seq 1 ${#GRIDKEYS[@]}); do
let MYKEY--
docker exec --user grid ${MYHOST?} sh -c "echo ${GRIDKEYS[${MYKEY?}]} >> ~/.ssh/authorized_keys"
done || echo "Unable to add grid public SSH keys on ${MYHOST}"
for MYKEY in $(seq 1 ${#ORACLEKEYS[@]}); do
let MYKEY--
docker exec --user oracle ${MYHOST?} sh -c "echo ${ORACLEKEYS[${MYKEY?}]} >> ~/.ssh/authorized_keys"
done || echo "Unable to add oracle public SSH keys on ${MYHOST}"
docker exec ${MYHOST?} sh -c "chmod 600 ~/.ssh/authorized_keys"
docker exec --user grid ${MYHOST?} sh -c "chmod 600 ~/.ssh/authorized_keys"
docker exec --user oracle ${MYHOST?} sh -c "chmod 600 ~/.ssh/authorized_keys"
done