create-lxc: drop sshd, enable tty1 auto-login instead

Access is now via the Proxmox web Console (or pct enter) — no SSH,
no keys, no passwords. /etc/inittab's tty1 line is rewritten to
`getty -n -l /usr/local/sbin/autologin-root` which execs `login -f root`,
dropping straight into a root shell when the Console button is clicked.
This commit is contained in:
d4nn13 committed 2026-04-19 19:19:07 +02:00
1 parent 1ab70a6f9a
commit 4c9df1941d
2 files changed
+28 -51

No files matched your search

+22 -39
View File
@@ -40,30 +40,6 @@ fi
log() { printf '[create-lxc] %s\n' "$*"; }
# --- SSH key injection ------------------------------------------------------
# Passwordless access. Always authorize the Proxmox host's root key (create
# an ed25519 pair if none exists) so `ssh root@<lxc>` from *this* host works
# out of the box. Additional keys via SSH_PUBKEY (one key per line, or a
# path to a file containing keys).
PUBKEYS=""
HOST_KEY="${HOST_KEY:-/root/.ssh/id_ed25519}"
if [[ ! -f "$HOST_KEY" ]]; then
log "generating Proxmox root SSH key at $HOST_KEY (none existed)"
install -d -m 0700 /root/.ssh
ssh-keygen -t ed25519 -N "" -f "$HOST_KEY" -C "root@$(hostname)" >/dev/null
fi
PUBKEYS="$(cat "${HOST_KEY}.pub")"
if [[ -n "${SSH_PUBKEY:-}" ]]; then
# treat as path if it looks like one, otherwise inline value
if [[ -f "$SSH_PUBKEY" ]]; then
PUBKEYS+=$'\n'"$(cat "$SSH_PUBKEY")"
else
PUBKEYS+=$'\n'"$SSH_PUBKEY"
fi
fi
# --- web UI autostart -------------------------------------------------------
# WIRECON_WEB_AUTOSTART=yes|no overrides the prompt. Default: yes (the UI is
# how you'll edit wg0.conf / wirecon.conf without drop-to-shell).
@@ -154,19 +130,25 @@ pct exec "$VMID" -- sh -c 'apk add --no-cache bash curl ca-certificates >/dev/nu
log "running bootstrap from $BOOTSTRAP_URL"
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' | WIRECON_REPO='$WIRECON_REPO' WIRECON_REF='$WIRECON_REF' bash"
# --- install sshd + authorize keys (passwordless) ---------------------------
log "installing sshd + authorizing $(printf '%s\n' "$PUBKEYS" | grep -c '^ssh-') key(s)"
# Alpine's default sshd_config is `PermitRootLogin prohibit-password` which
# allows root login with keys and rejects passwords — exactly what we want.
# No sshd_config edits needed.
printf '%s\n' "$PUBKEYS" | pct exec "$VMID" -- sh -c '
apk add --no-cache openssh >/dev/null
install -d -m 0700 /root/.ssh
cat >> /root/.ssh/authorized_keys
sort -u /root/.ssh/authorized_keys -o /root/.ssh/authorized_keys
chmod 0600 /root/.ssh/authorized_keys
rc-update add sshd default >/dev/null
rc-service sshd restart >/dev/null
# --- tty1 auto-login (for Proxmox web Console) ------------------------------
# Drop a /usr/local/sbin/autologin-root wrapper and point getty at it so the
# Proxmox "Console" button lands directly in a root shell. Security posture
# is unchanged in practice — anyone who can open the web console already has
# `pct enter` on the host.
log "enabling tty1 auto-login"
pct exec "$VMID" -- sh -c 'cat > /usr/local/sbin/autologin-root && chmod 0755 /usr/local/sbin/autologin-root' <<'AUTOLOGIN'
#!/bin/sh
exec /bin/login -f root
AUTOLOGIN
pct exec "$VMID" -- sh -c '
# Replace the tty1 getty line; if none exists, append one.
if grep -qE "^tty1::" /etc/inittab; then
sed -i "s|^tty1::respawn:.*|tty1::respawn:/sbin/getty -n -l /usr/local/sbin/autologin-root 38400 tty1|" /etc/inittab
else
echo "tty1::respawn:/sbin/getty -n -l /usr/local/sbin/autologin-root 38400 tty1" >> /etc/inittab
fi
kill -HUP 1 2>/dev/null || true
'
# --- optional: start web UI -------------------------------------------------
@@ -182,11 +164,12 @@ fi
cat <<EOF
[create-lxc] container $VMID ($HOSTNAME) provisioned.
[create-lxc] shell: ssh root@${ip:-<lxc-ip>} (passwordless, key-only)
[create-lxc] shell: open Console in the Proxmox UI → root shell, no prompt
[create-lxc] (or from the host: pct enter $VMID)
${WEB_URL:+[create-lxc] web UI: $WEB_URL}
[create-lxc] finish configuration:
- edit /etc/wireguard/wg0.conf and /etc/wirecon/wirecon.conf
(via the web UI above, or over ssh / pct enter)
(via the web UI above, or the Proxmox Console)
- then start the tunnel services:
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start