-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·72 lines (51 loc) · 1.94 KB
/
entrypoint.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
#!/bin/sh
cat <<EOF
################################################################################
Welcome to the ghcr.io/servercontainers/sshtunnel
################################################################################
You'll find this container sourcecode here:
https://github.com/ServerContainers/sshtunnel
The container repository will be updated regularly.
################################################################################
EOF
if [ ! -e '/initialized' ]; then
touch '/initialized'
echo ">> harden ssh config"
sed -i 's/.*PermitRootLogin.*/PermitRootLogin no/g' /etc/ssh/sshd_config
sed -i 's/.*PasswordAuthentication.*/PasswordAuthentication no/g' /etc/ssh/sshd_config
sed -i 's/.*X11Forwarding.*/X11Forwarding no/g' /etc/ssh/sshd_config
echo ">> add users"
env | grep '^USER_' | while read I_ACCOUNT
do
ACCOUNT_NAME=$(echo "$I_ACCOUNT" | cut -d'=' -f1 | sed 's/USER_//g' | tr '[:upper:]' '[:lower:]')
ACCOUNT_PUB_KEY=$(echo "$I_ACCOUNT" | sed 's/^[^=]*=//g')
echo " >> create account: $ACCOUNT_NAME"
useradd -m -s /bin/false "$ACCOUNT_NAME"
mkdir -p "/home/$ACCOUNT_NAME/.ssh"
echo "$ACCOUNT_PUB_KEY" > "/home/$ACCOUNT_NAME/.ssh/authorized_keys"
chown "$ACCOUNT_NAME" -R "/home/$ACCOUNT_NAME/.ssh"
chmod 700 "/home/$ACCOUNT_NAME/.ssh"
chmod 600 "/home/$ACCOUNT_NAME/.ssh/authorized_keys"
echo " >> add ssh config"
echo 'Match User '"$ACCOUNT_NAME"'
AllowTcpForwarding yes
X11Forwarding no
PermitTunnel no
GatewayPorts no
AllowAgentForwarding no
ForceCommand echo "This Account can only be used for SSH Port Forwarding"
' >> /etc/ssh/sshd_config
env | grep '^'$(echo "$I_ACCOUNT" | sed 's/USER_/PERMIT_OPEN_/g' | sed 's/=.*//g') | while read PERMIT_OPEN_RAW
do
PERMIT_OPEN=$(echo "$PERMIT_OPEN_RAW" | sed 's/^[^=]*=//g')
echo " PermitOpen $PERMIT_OPEN"
echo " PermitOpen $PERMIT_OPEN" >> /etc/ssh/sshd_config
done
done
fi
##
# CMD
##
echo ">> CMD: exec docker CMD"
echo "$@"
exec "$@"