Files
ubuntu-post-install/services
Claude 9c5d8c32f7 Reuse the sudo user's SSH key for root; make B2 rejection unambiguous
Two separate fixes from a live report.

1. The DR-spare and SFTP-mirror sections both checked ONLY /root/.ssh
   for a key, missing the common case: the person running `sudo
   ./setup.sh backup` already has a key under their own home directory
   (used interactively, quite possibly already authorized on the target
   box), while root — who actually runs the scheduled systemd service —
   has none. Confirmed live: "the computer has the ssh key for the sudo
   user on the box" produced "No SSH key found for root" with no
   inline way to do anything about it beyond a pointer to go set one up
   elsewhere and re-run.

   Factored both call sites into one shared _backup_ensure_root_ssh_key()
   that checks root first, then offers to reuse the sudo user's existing
   keypair (copied into /root/.ssh with correct ownership/permissions,
   root:root 600) before falling back to generating a brand new one —
   reusing an existing key can work immediately if it's already
   authorized on the target, where a fresh key needs a new ssh-copy-id
   round-trip regardless. Verified all three branches (root already has
   a key, root has none but the user does and accepts reuse, neither
   exists and one gets generated) against a mocked filesystem.

2. The B2 dry-run failure message read like it could be about missing
   input even when every field was non-empty — confirmed there's no
   code path where non-blank-but-wrong values actually trigger the
   separate "Left blank" message (the two are on disjoint branches), but
   the dry-run failure text itself didn't rule that out or point at the
   actual likely cause. Now echoes back what was entered (bucket,
   endpoint, Key ID — never the secret) so it's easy to eyeball against
   B2's own confirmation screen, states plainly that this is a rejection
   of non-blank input, and names the most likely cause directly: pairing
   the Key ID from one Application Key with the Secret from a different
   one, which is easy to do after creating more than one while
   troubleshooting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn
2026-08-14 13:11:44 +00:00
..