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:
1 parent
1ab70a6f9a
commit
4c9df1941d
2 files changed
+28
-51
No files matched your search
@@ -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)"
|
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 <VMID>` 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@<lxc-ip>` from the Proxmox host works immediately.
|
- `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.
|
||||||
- **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:
|
- This is safe in practice: anyone who can open the web Console is already a Proxmox admin and could `pct enter` anyway.
|
||||||
|
|
||||||
```
|
|
||||||
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 <VMID>` from the Proxmox host remains available as a fallback.
|
|
||||||
|
|
||||||
## Finishing up (inside the LXC)
|
## Finishing up (inside the LXC)
|
||||||
|
|
||||||
|
|||||||
+22
-39
@@ -40,30 +40,6 @@ fi
|
|||||||
|
|
||||||
log() { printf '[create-lxc] %s\n' "$*"; }
|
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 -------------------------------------------------------
|
# --- web UI autostart -------------------------------------------------------
|
||||||
# WIRECON_WEB_AUTOSTART=yes|no overrides the prompt. Default: yes (the UI is
|
# 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).
|
# 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"
|
log "running bootstrap from $BOOTSTRAP_URL"
|
||||||
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' | WIRECON_REPO='$WIRECON_REPO' WIRECON_REF='$WIRECON_REF' bash"
|
pct exec "$VMID" -- sh -c "curl -fsSL '$BOOTSTRAP_URL' | WIRECON_REPO='$WIRECON_REPO' WIRECON_REF='$WIRECON_REF' bash"
|
||||||
|
|
||||||
# --- install sshd + authorize keys (passwordless) ---------------------------
|
# --- tty1 auto-login (for Proxmox web Console) ------------------------------
|
||||||
log "installing sshd + authorizing $(printf '%s\n' "$PUBKEYS" | grep -c '^ssh-') key(s)"
|
# Drop a /usr/local/sbin/autologin-root wrapper and point getty at it so the
|
||||||
# Alpine's default sshd_config is `PermitRootLogin prohibit-password` which
|
# Proxmox "Console" button lands directly in a root shell. Security posture
|
||||||
# allows root login with keys and rejects passwords — exactly what we want.
|
# is unchanged in practice — anyone who can open the web console already has
|
||||||
# No sshd_config edits needed.
|
# `pct enter` on the host.
|
||||||
printf '%s\n' "$PUBKEYS" | pct exec "$VMID" -- sh -c '
|
log "enabling tty1 auto-login"
|
||||||
apk add --no-cache openssh >/dev/null
|
pct exec "$VMID" -- sh -c 'cat > /usr/local/sbin/autologin-root && chmod 0755 /usr/local/sbin/autologin-root' <<'AUTOLOGIN'
|
||||||
install -d -m 0700 /root/.ssh
|
#!/bin/sh
|
||||||
cat >> /root/.ssh/authorized_keys
|
exec /bin/login -f root
|
||||||
sort -u /root/.ssh/authorized_keys -o /root/.ssh/authorized_keys
|
AUTOLOGIN
|
||||||
chmod 0600 /root/.ssh/authorized_keys
|
|
||||||
rc-update add sshd default >/dev/null
|
pct exec "$VMID" -- sh -c '
|
||||||
rc-service sshd restart >/dev/null
|
# 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 -------------------------------------------------
|
# --- optional: start web UI -------------------------------------------------
|
||||||
@@ -182,11 +164,12 @@ fi
|
|||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
[create-lxc] container $VMID ($HOSTNAME) provisioned.
|
[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}
|
${WEB_URL:+[create-lxc] web UI: $WEB_URL}
|
||||||
[create-lxc] finish configuration:
|
[create-lxc] finish configuration:
|
||||||
- edit /etc/wireguard/wg0.conf and /etc/wirecon/wirecon.conf
|
- 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:
|
- then start the tunnel services:
|
||||||
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
|
rc-update add wg-quick.wg0 default && rc-service wg-quick.wg0 start
|
||||||
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
|
rc-update add wirecon-watchdog default && rc-service wirecon-watchdog start
|
||||||
|
|||||||
Reference in new issue
Block a user