LXC: add CONSOLE_AUTOLOGIN option for root autologin on the Proxmox console

This commit is contained in:
zyphlar
2026-11-02 01:55:06 -08:00
parent 01266e9d28
commit 62ad14ac93
2 changed files with 31 additions and 8 deletions
+27 -6
View File
@@ -12,8 +12,10 @@
# GATEWAY [] VLAN [] CORES [1] MEMORY [512] DISK [4] PORT [3000]
# SMTP_URL MAIL_FROM SITE_NAME DIGEST_HOUR TZ [host's timezone]
# ROOT_PASSWORD [] SSH_PUBLIC_KEYS [] (a file of public keys for root)
# Without ROOT_PASSWORD, root can't log in at the Proxmox console; use
# `pct enter <ctid>` on the host instead. ADMIN_PASSWORD is only for /admin.
# CONSOLE_AUTOLOGIN [0] (1: the Proxmox console logs in as root, no password)
# Without ROOT_PASSWORD or CONSOLE_AUTOLOGIN=1, root can't log in at the
# Proxmox console; use `pct enter <ctid>` on the host instead.
# ADMIN_PASSWORD is only for /admin.
set -euo pipefail
die () { echo "error: $*" >&2; exit 1; }
@@ -40,6 +42,8 @@ CORES=${CORES:-1}
MEMORY=${MEMORY:-512}
DISK=${DISK:-4}
PORT=${PORT:-3000}
CONSOLE_AUTOLOGIN=${CONSOLE_AUTOLOGIN:-0}
case "$CONSOLE_AUTOLOGIN" in 0|1) ;; *) die "CONSOLE_AUTOLOGIN must be 0 or 1" ;; esac
TZ=${TZ:-$(cat /etc/timezone 2>/dev/null || timedatectl show -p Timezone --value 2>/dev/null || echo Etc/UTC)}
net="name=eth0,bridge=$BRIDGE,ip=$IP"
@@ -86,11 +90,28 @@ fi
{
printf 'Immich Magic Proxy (Debian \\r)\n\n'
printf ' Web: http://\\4{eth0}:%s Admin: %s/admin\n' "$PORT" "$PUBLIC_BASE_URL"
printf ' Login: root at this console needs ROOT_PASSWORD set at install;\n'
printf ' otherwise run "pct enter %s" on the Proxmox host.\n' "$CTID"
printf ' The /admin password is not the root password.\n\n'
if [ "$CONSOLE_AUTOLOGIN" != 1 ]; then
printf ' Login: root at this console needs ROOT_PASSWORD set at install;\n'
printf ' otherwise run "pct enter %s" on the Proxmox host.\n' "$CTID"
printf ' The /admin password is not the root password.\n'
fi
printf '\n'
} | pct exec "$CTID" -- sh -c 'cat > /etc/issue'
# Console autologin: the Proxmox console (tty1, served by container-getty@1)
# logs straight in as root. Anyone with console access to this container in
# Proxmox gets root in it; SSH still can't log in as root without a key.
if [ "$CONSOLE_AUTOLOGIN" = 1 ]; then
log "Enabling root autologin on the Proxmox console"
pct exec "$CTID" -- sh -c 'd=/etc/systemd/system/container-getty@1.service.d
install -d -m 0755 "$d"
printf "%s\n" "[Service]" "ExecStart=" \
"ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud tty%I 115200,38400,9600 \$TERM" \
> "$d/autologin.conf"
systemctl daemon-reload
systemctl restart container-getty@1'
fi
log "Waiting for the network"
for _ in $(seq 1 60); do
pct exec "$CTID" -- sh -c 'getent hosts deb.debian.org >/dev/null' && break
@@ -150,7 +171,7 @@ Immich Magic Proxy is running in container $CTID at http://$address:$PORT
Next:
1. Point your reverse proxy for $PUBLIC_BASE_URL at http://$address:$PORT
2. Open $PUBLIC_BASE_URL/admin and sign in with ADMIN_PASSWORD
Shell: pct enter $CTID (the console login needs ROOT_PASSWORD; /admin uses ADMIN_PASSWORD)
Shell: pct enter $CTID (or the Proxmox console, with ROOT_PASSWORD or CONSOLE_AUTOLOGIN=1)
Settings: pct exec $CTID -- nano /etc/immich-magic-proxy/env (then: systemctl restart immich-magic-proxy)
Logs: pct exec $CTID -- journalctl -u immich-magic-proxy -f
Upgrade: pct push $CTID <new tarball> /root/release.tar.gz && pct push $CTID install.sh /root/install.sh --perms 0755 &&