Documentation
¶
Overview ¶
Package sshutil holds the small SSH helpers shared by the CLI and the TUI: installing a public key into a live guest's authorized_keys over SSH. It lives outside cmd so internal/tui (which cannot import cmd) can reuse the exact same logic behind `hlab {vm,ct} add-ssh-key` and the dashboard's inject-key action.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendAuthorizedKey ¶
AppendAuthorizedKey installs a public key into a live guest's ~/.ssh/authorized_keys over SSH, non-interactively (BatchMode) and idempotently: it creates ~/.ssh (700) and authorized_keys (600) if missing and appends the key only when the exact line isn't already present (grep -qxF).
BatchMode=yes disables every interactive prompt (notably the password prompt), so this NEVER blocks asking for a password: if the guest doesn't already trust a key hlab can use, ssh fails with "Permission denied" instead of prompting. That auth failure is translated into an actionable message (see authFailureHint) rather than a raw ssh dump — the usual cause is a keyless guest whose sshd refuses password auth (e.g. an LXC container's root, PermitRootLogin prohibit-password), which no amount of retrying over SSH can fix.
func AuthorizedKeyCommand ¶
AuthorizedKeyCommand returns the idempotent shell command that appends pubKey to the login user's ~/.ssh/authorized_keys. Shared by both install paths — SSH (AppendAuthorizedKey) and the Proxmox console (engine.InjectSSHKeyViaConsole, which logs in as root, where ~ is /root) — so the key is installed identically however hlab reaches the guest.
func AuthorizedKeyCommandFor ¶
AuthorizedKeyCommandFor returns the idempotent `/bin/sh -c` script that appends an SSH public key to a NAMED user's ~/.ssh/authorized_keys with correct ownership and permissions. Unlike AuthorizedKeyCommand (which targets the connection user's ~, i.e. root over the LXC console), this resolves the user's home via `getent passwd` and chowns everything to that user — it is used by the VM guest-agent path (engine.InjectSSHKeyViaAgent), where the agent runs as root but the key belongs to the unprivileged login user.
The key is NOT embedded in the script: it is read from stdin (`key=$(cat)`), so the caller feeds it via the guest agent's input-data. That avoids shell-quoting the key into the command entirely — the script is identical for every key.
func KeylessAddKeyError ¶
KeylessAddKeyError is the error returned by the add-ssh-key / inject-key flows when a key cannot be installed at all. For a VM the recovery channel is the QEMU guest agent (engine.InjectSSHKeyViaAgent), so the VM branch is the fallback shown only when that channel can't be used — the agent isn't running or the token lacks VM.GuestAgent.Unrestricted (the real agent/privilege error is threaded up instead where possible). For a container hlab CAN inject the first key over the Proxmox console using the root password: it uses the stored password, or prompts for it (or takes `--password`), so a keyless container is recoverable as long as you know the root password. This error is for the case where even that is impossible (no password stored, none entered, and no prompt available — e.g. a non-interactive run). The fix is to supply the root password or seed a key out of band. Shared by the CLI handler, the TUI inject flow and the engine's console injection.
Types ¶
This section is empty.