2022-09-09 11:37:37 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2022-09-15 14:31:45 +02:00
|
|
|
set -ex
|
|
|
|
|
2022-09-09 11:37:37 +02:00
|
|
|
mkdir -p /run/sshd
|
|
|
|
|
2022-09-15 14:30:12 +02:00
|
|
|
if [ -n "$ROOT_AUTHORIZED_KEYS" ]; then
|
|
|
|
if [ -f "$ROOT_AUTHORIZED_KEYS" ]; then
|
|
|
|
mkdir -p /root/.ssh
|
|
|
|
cp "$ROOT_AUTHORIZED_KEYS" /root/.ssh/authorized_keys
|
|
|
|
chmod 600 /root/.ssh/authorized_keys
|
|
|
|
fi
|
|
|
|
fi
|
2022-09-09 11:37:37 +02:00
|
|
|
|
2022-09-15 14:31:45 +02:00
|
|
|
if [ -z "$BASE_DIR" ]; then
|
|
|
|
BASE_DIR="/home"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -d "$BASE_DIR" ]; then
|
|
|
|
echo "BASE_DIR $BASE_DIR does not exist, creating..."
|
|
|
|
mkdir -p $BASE_DIR
|
|
|
|
fi
|
|
|
|
|
|
|
|
# GROUPADD="group1:1000;group2:1001;group3:1002"
|
|
|
|
while [ "$GROUPADD" != "$i" ] ;do
|
|
|
|
i=${GROUPADD%%;*}
|
|
|
|
GROUPADD="${GROUPADD#$i;}"
|
|
|
|
|
|
|
|
GROUP_NAME=${i%%:*}
|
|
|
|
GROUP_GID="${i#$GROUP_NAME:}"
|
|
|
|
|
|
|
|
groupadd --gid "$GROUP_GID" "$GROUP_NAME"
|
|
|
|
done
|
|
|
|
|
|
|
|
# USERADD="user1:1000:1000;user2:1001:1000;user3:1002:1002"
|
|
|
|
while [ "$USERADD" != "$i" ] ;do
|
|
|
|
i=${USERADD%%;*}
|
|
|
|
USERADD="${USERADD#$i;}"
|
|
|
|
|
|
|
|
USER_NAME=${i%%:*}
|
|
|
|
UID_GID="${i#$USER_NAME:}"
|
|
|
|
USER_UID="${UID_GID%%:*}"
|
|
|
|
USER_GID="${UID_GID#$USER_UID:}"
|
|
|
|
|
|
|
|
useradd --home-dir "$BASE_DIR/$USER_NAME" --uid "$USER_UID" --gid "$USER_GID" "$USER_NAME"
|
|
|
|
done
|
|
|
|
|
2022-09-17 14:20:16 +02:00
|
|
|
if [ -z "$(find /etc/ssh/ -maxdepth 1 -name 'ssh_host_*_key' -print -quit)" ]; then
|
|
|
|
echo "Creating SSH2 ED25519 key; this may take some time ..."
|
|
|
|
ssh-keygen -q -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
|
|
|
|
ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub
|
|
|
|
echo "HostKey /etc/ssh/ssh_host_ed25519_key" >> /etc/ssh/sshd_config
|
|
|
|
fi
|
|
|
|
|
2022-09-09 11:37:37 +02:00
|
|
|
exec /usr/sbin/sshd -D -e
|