From 4c9df1941db4bd7262023f8dce76f61cb32c8393 Mon Sep 17 00:00:00 2001 From: d4nn13 Date: Sun, 19 Apr 2026 19:19:07 +0200 Subject: [PATCH] create-lxc: drop sshd, enable tty1 auto-login instead MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- README.md | 18 +++++-------- proxmox/create-lxc.sh | 61 ++++++++++++++++--------------------------- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 9650f79..315af1f 100644 --- a/README.md +++ b/README.md @@ -34,22 +34,16 @@ HOSTNAME=tunbox MEMORY=512 STORAGE=fast-nvme \ bash -c "$(curl -fsSL https://git.d4nn13.de/d4nn13/wirecon/raw/branch/main/proxmox/create-lxc.sh)" ``` -Available overrides: `HOSTNAME`, `CORES`, `MEMORY`, `DISK`, `BRIDGE`, `STORAGE`, `TEMPLATE_STORAGE`, `WIRECON_REPO`, `WIRECON_REF`, `SSH_PUBKEY`, `WIRECON_WEB_AUTOSTART` (yes/no). +Available overrides: `HOSTNAME`, `CORES`, `MEMORY`, `DISK`, `BRIDGE`, `STORAGE`, `TEMPLATE_STORAGE`, `WIRECON_REPO`, `WIRECON_REF`, `WIRECON_WEB_AUTOSTART` (yes/no). -The script also asks (interactively, default **yes**) whether to enable the web UI on boot. Edit configs in-browser right after provisioning instead of `vi`'ing over `pct enter`. +The script also asks (interactively, default **yes**) whether to enable the web UI on boot. Edit configs in-browser right after provisioning. -### Shell access (passwordless, key-only) +### Shell access -No password is ever set. The script installs `openssh`, enables `sshd`, and authorizes root SSH keys: +No password, no SSH. Access is via the Proxmox **Console** button or `pct enter ` from the host: -- **Always added:** the Proxmox host's `/root/.ssh/id_ed25519.pub`. The script generates this keypair if it doesn't exist, so `ssh root@` from the Proxmox host works immediately. -- **Optionally added:** whatever you pass in `SSH_PUBKEY` — either a literal key string or a path to a file containing one or more keys. Example: - - ``` - SSH_PUBKEY=~/.ssh/id_ed25519.pub bash -c "$(curl -fsSL …/create-lxc.sh)" - ``` - -Alpine's default `PermitRootLogin prohibit-password` stays in place — root is reachable with a key, password auth is refused. `pct enter ` from the Proxmox host remains available as a fallback. +- `tty1` is wired to `getty -n -l /usr/local/sbin/autologin-root`, which execs `login -f root` → you land directly in a root shell with no prompt. +- This is safe in practice: anyone who can open the web Console is already a Proxmox admin and could `pct enter` anyway. ## Finishing up (inside the LXC) diff --git a/proxmox/create-lxc.sh b/proxmox/create-lxc.sh index a5c5ec7..ecbb82c 100755 --- a/proxmox/create-lxc.sh +++ b/proxmox/create-lxc.sh @@ -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@` 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 <} (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