-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
34 lines (28 loc) · 931 Bytes
/
run.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
#!/bin/bash
mkdir /var/run/sshd
mkdir -p /root/.ssh
chmod 700 /root/.ssh
touch /root/.ssh/authorized_keys
chmod 600 /root/.ssh/*
chown -Rf root:root /root/.ssh
# configure sshd to block authentication via password
sed -i.bak 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
rm /etc/ssh/sshd_config.bak
if [ "${AUTHORIZED_KEYS}" != "**None**" ]; then
echo "=> Found authorized keys"
IFS=$'\n'
arr=$(echo ${AUTHORIZED_KEYS} | tr "," "\n")
for x in $arr
do
x=$(echo $x | sed -e 's/^ *//' -e 's/ *$//')
cat /app/authorized_keys.tmpl | grep "$x" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "=> Adding public key to authorized_keys.tmpl: $x"
echo "$x" >> /app/authorized_keys.tmpl
fi
done
else
echo "ERROR: No authorized keys found in \$AUTHORIZED_KEYS"
exit 1
fi
exec supervisord -c /etc/supervisord.conf -n