K-114: SSH root login prompt with sshd drop-in in the install path

prompt_lxc_config asks 'SSH-Root-Login erlauben? [Y/n]' (env-presettable
via SSH_ROOT_LOGIN, validated, normalized to yes|no). The bootstrap passes
the value into the container; configure_ssh_root_login writes
/etc/ssh/sshd_config.d/zz-root-login.conf (yes -> PermitRootLogin yes,
no -> prohibit-password) and reloads sshd.
This commit is contained in:
2026-06-12 14:41:31 +02:00
parent 5f532fe10a
commit aa3ad2f716
8 changed files with 95 additions and 5 deletions
+30
View File
@@ -38,6 +38,36 @@ apt_cleanup() {
apt-get autoclean -qq >/dev/null || true
}
# ── ssh ──────────────────────────────────────────────────────────────────────
# SSH-Root-Login gemäß Host-Prompt (prompt_lxc_config setzt SSH_ROOT_LOGIN,
# bootstrap_install_script reicht es als Env durch; Default: yes).
# yes → PermitRootLogin yes (Passwort-Login mit dem generierten Root-Passwort)
# no → PermitRootLogin prohibit-password (Debian-Default, nur SSH-Key)
# Umsetzung als Drop-in, damit Paket-Updates von sshd_config nicht kollidieren.
configure_ssh_root_login() {
local choice="${SSH_ROOT_LOGIN:-yes}" value
case "$choice" in
yes) value="yes" ;;
no) value="prohibit-password" ;;
*) msg_err "SSH_ROOT_LOGIN must be yes|no, got: '$choice'"; return 1 ;;
esac
if [[ ! -d /etc/ssh/sshd_config.d ]]; then
if [[ "$choice" == "no" ]]; then
msg_warn "openssh-server not installed — nothing to configure (root login stays off)"
return 0
fi
msg_info "Installing openssh-server..."
apt-get install -y -qq openssh-server >/dev/null
fi
msg_info "Configuring SSH root login: PermitRootLogin $value"
printf 'PermitRootLogin %s\n' "$value" >/etc/ssh/sshd_config.d/zz-root-login.conf
systemctl reload ssh 2>/dev/null || systemctl restart ssh 2>/dev/null \
|| msg_warn "ssh.service not active yet — config applies on first start"
msg_ok "SSH root login: $choice"
}
# ── users / dirs ─────────────────────────────────────────────────────────────
create_system_user() {
local user="$1" home="$2"