From 62ad14ac9391dd500cddde5c4db6daaffc478ceb Mon Sep 17 00:00:00 2001 From: zyphlar Date: Mon, 2 Nov 2026 01:55:06 -0800 Subject: [PATCH] LXC: add CONSOLE_AUTOLOGIN option for root autologin on the Proxmox console --- lxc/README.md | 6 ++++-- lxc/proxmox-create.sh | 33 +++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/lxc/README.md b/lxc/README.md index 1568e55..cb9c104 100644 --- a/lxc/README.md +++ b/lxc/README.md @@ -30,11 +30,13 @@ It downloads the Debian 13 template if needed and creates an unprivileged contai It then installs everything and prints the container's address. Optional settings: `CTID`, `CT_HOSTNAME`, `STORAGE` (`local-lvm`), `TEMPLATE_STORAGE` (`local`), `BRIDGE` (`vmbr0`), `IP` (`dhcp` or `192.168.1.50/24`), `GATEWAY`, `VLAN`, `CORES` (1), `MEMORY` (512 MB), `DISK` (4 GB), `PORT` (3000), `SITE_NAME`, `DIGEST_HOUR`, `TZ` (defaults to -the host's), `ROOT_PASSWORD`, `SSH_PUBLIC_KEYS` (a file of keys for root), and +the host's), `ROOT_PASSWORD`, `SSH_PUBLIC_KEYS` (a file of keys for root), `CONSOLE_AUTOLOGIN` (0), and `SMTP_HOST`/`SMTP_PORT`/`SMTP_USER`/`SMTP_PASS`/`SMTP_SECURE` instead of `SMTP_URL`. `ADMIN_PASSWORD` is only for the web `/admin` page, not the container's root account. To log in at the Proxmox -console, set `ROOT_PASSWORD`. Without it, get a shell with `pct enter ` on the host. The console's login screen +console, set `ROOT_PASSWORD`, or set `CONSOLE_AUTOLOGIN=1` to have the console log in as root with no password. +Anyone who can open the container's console in Proxmox then gets root in it; SSH still can't log in as root without a +key. Without either, get a shell with `pct enter ` on the host. The console's login screen shows the container's address and the `/admin` URL. Then point your reverse proxy (HTTPS) at the container's port 3000, open `/admin`, and sign in. diff --git a/lxc/proxmox-create.sh b/lxc/proxmox-create.sh index 2afd606..3b45726 100755 --- a/lxc/proxmox-create.sh +++ b/lxc/proxmox-create.sh @@ -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 ` 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 ` 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 /root/release.tar.gz && pct push $CTID install.sh /root/install.sh --perms 0755 &&