-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmake_ssh_keys.sh
79 lines (69 loc) · 1.93 KB
/
make_ssh_keys.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
79
#!/bin/bash
#
# $Id: make_ssh_keys.sh 3.12 2017-03-07 17:04:25 cmayer $
# ha setup requires ssh keys on both nodes for the appdynamics user
#
# this script creates the keys and plugs them in to both nodes.
# it will prompt for passwords to propagate the keys
#
# Copyright 2016 AppDynamics, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export PATH=/bin:/usr/bin:/sbin:/usr/sbin
#
# make 2 keypairs
#
primary=`hostname`
secondary=
function usage {
echo "usage: $0 [options]"
echo " -s <secondary host name>"
echo " -h get help"
exit 1
}
while getopts s:h flag; do
case $flag in
s)
secondary=$OPTARG
;;
h)
usage
;;
esac
done
if [ -z "$secondary" ] ; then
echo "must specify secondary hostname"
usage
fi
if [ -d ~/.ssh ] ; then
echo ~/.ssh already exists
exit 2
fi
if [ -f ~/.ssh/authorized_hosts ] ; then
echo ~/.ssh/authorized_hosts already exists
exit 3
fi
PRIMARY_SSH=/tmp/key-create/$primary/.ssh
SECONDARY_SSH=/tmp/key-create/$secondary/.ssh
mkdir -p $PRIMARY_SSH
mkdir -p $SECONDARY_SSH
chmod 600 $PRIMARY_SSH
chmod 600 $SECONDARY_SSH
ssh-keygen -N "" -f $PRIMARY_SSH/id_rsa >/dev/null 2>&1
ssh-keygen -N "" -f $SECONDARY_SSH/id_rsa >/dev/null 2>&1
cat $PRIMARY_SSH/id_rsa.pub $SECONDARY_SSH/authorized_hosts
cp $SECONDARY_SSH/id_rsa.pub $PRIMARY_SSH/authorized_hosts
chmod 600 $PRIMARY_SSH/authorized_hosts
chmod 600 $SECONDARY_SSH/authorized_hosts
scp -rp $SECONDARY_SSH secondary:
cp -rp $PRIMARY_SSH ~