enable keypair auth and some refactoring

This commit is contained in:
Dennis Hermsmeier
2018-12-01 15:31:55 +01:00
parent 279065bbec
commit 6f1544c7f0
4 changed files with 77 additions and 16 deletions

View File

@@ -3,9 +3,19 @@
# generate host keys if not present
ssh-keygen -A
# check wether a random root-password is provided
if [ ! -z "${ROOT_PASSWORD}" ] && [ "${ROOT_PASSWORD}" != "root" ]; then
echo "root:${ROOT_PASSWORD}" | chpasswd
# set root login mode by password or keypair
if [ "${KEYPAIR_LOGIN}" = "true" ] && [ -f "${HOME}/.ssh/authorized_keys" ] ; then
sed -i "s/#PermitRootLogin.*/PermitRootLogin without-password/" /etc/ssh/sshd_config
sed -i "s/#PasswordAuthentication.*/PasswordAuthentication no/" /etc/ssh/sshd_config
echo "Enabled root-login by keypair and disabled password-login"
else
sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config
set +x
if [ -n "${ROOT_PASSWORD}" ] && [ "${ROOT_PASSWORD}" != "root" ]; then
echo "root:${ROOT_PASSWORD}" | chpasswd
fi
set -x
echo "Enabled root-login by password"
fi
# do not detach (-D), log to stderr (-e), passthrough other arguments