gf-k8s/SSHct/entrypoint.sh
Andrey Kartashov 937f057686 SSHct: allowed to save user password in /home/.$CTUSER.shadow
File should be owned by root.root and mode should be 640

Otherwise entrypoint.sh will fall back to $CTUSERPWD
2018-01-23 00:21:06 +07:00

35 lines
1.1 KiB
Bash

#!/bin/sh
echo $CTTIMEZONE > /etc/timezone
ln -sf /usr/share/zoneinfo/$CTTIMEZONE /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
sed -i -e "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen
sed -i -e "s/# $CTLOCALE UTF-8/$CTLOCALE UTF-8/" /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
update-locale LANG=$CTLOCALE
echo "AllowUsers $CTUSER" >> /etc/ssh/sshd_config
useradd --uid $CTUSERID --user-group --shell /bin/bash $CTUSER
if [ -f /home/.$CTUSER.shadow -a \
"$(stat --dereference --printf='%u %g %a' /home/.$CTUSER.shadow)" == "0 0 640" ]; then
echo $CTUSER:"$(cat /home/.$CTUSER.shadow)" | chpasswd -e
else
echo $CTUSER:"$CTUSERPWD" | chpasswd
fi
passwd -u $CTUSER
usermod -a -G sudo $CTUSER
# Add pubkey
if [ "$PUBKEY" != "none" ]; then
echo "$PUBKEY" >> /home/$CTUSER/.ssh/authorized_keys
chmod 600 /home/$CTUSER/.ssh/authorized_keys
fi
# Install additional packages in background
if [ -f /home/.packages ]; then
tmux new-session -d -s aptget 'cat /home/.packages | xargs --max-args=1 apt-get install -y'
fi
# start ssh daemon
exec /usr/sbin/sshd -Def /etc/ssh/sshd_config