-
Notifications
You must be signed in to change notification settings - Fork 0
/
uesp-create-localkey
executable file
·113 lines (87 loc) · 1.97 KB
/
uesp-create-localkey
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh
#
# $1 = UESP hostname
#
echo "Starting uesp-create-localkey..."
UESPHOST="$1"
KEYPATH="/etc/uesp-keys/"
LOCALKEY="keys/local-uesp-key.pub"
create_server_key()
#
# $1 = UESP hostname
#
{
KEYFILE="keys/$1-uesp-key"
PUBKEYFILE="$KEYFILE.pub"
ssh-keygen -q -t rsa -b 4096 -a 100 -f $KEYFILE -C "$1.uesp.net" -N ""
RESULT=$?
if [ $RESULT != 0 ]
then
echo " ERROR: Failed to generate the public/private key pair!"
return -1
fi
cp -f $PUBKEYFILE $LOCALKEY
RESULT=$?
if [ $RESULT != 0 ]
then
echo " ERROR: Failed to copy the the public key to '$LOCALKEY'!"
return -2
fi
if [ ! -d $KEYPATH ]
then
mkdir $KEYPATH
RESULT=$?
if [ $RESULT != 0 ]
then
echo " ERROR: Failed to create directory '$KEYPATH'!"
return -3
fi
fi
HOMEPATH="/home/uespkey/.ssh"
if [ ! -d "$HOMEPATH" ]
then
mkdir -p "$HOMEPATH"
if [ $? != 0 ]
then
echo " ERROR: Failed to create directory '$HOMEPATH'!"
else
chown uespkey:uespkey "$HOMEPATH"
chmod 700 $HOMEPATH
fi
fi
cp -f $KEYFILE $HOMEPATH/id_rsa
chown uespkey:uespkey $HOMEPATH/id_rsa
chmod 600 $HOMEPATH/id_rsa
cp -f $KEYFILE /etc/uesp-keys/local-uesp-key
chown uespkey:uespkey /etc/uesp-keys/local-uesp-key
chmod 600 /etc/uesp-keys/local-uesp-key
touch $HOMEPATH/authorized_keys
chmod 600 $HOMEPATH/authorized_keys
HOMEPATH="/home/dave/.ssh"
if [ ! -d "$HOMEPATH" ]
then
mkdir -p "$HOMEPATH"
if [ $? != 0 ]
then
echo " ERROR: Failed to create directory '$HOMEPATH'!"
else
chown dave:dave "$HOMEPATH"
chmod 700 $HOMEPATH
fi
fi
cp -f $KEYFILE $HOMEPATH/id_rsa
chown dave:dave $HOMEPATH/id_rsa
chmod 600 $HOMEPATH/id_rsa
touch $HOMEPATH/authorized_keys
chmod 600 $HOMEPATH/authorized_keys
cp -f $PUBKEYFILE $KEYPATH
cp -f $LOCALKEY $KEYPATH
echo " OK: Created public/private key pair for host '$1'."
}
if [ -z $UESPHOST ]
then
echo " ERROR: Empty UESP hostname specified!"
exit -1
fi
mkdir -p keys
create_server_key "$UESPHOST"