From 350708ae10faf5f9348aaab638bee89f25858d46 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Aug 2026 03:26:01 +0000 Subject: [PATCH] Resolve ~/.ssh/config aliases before handing a host to Kopia's sync-to sftp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Confirmed: Kopia's sync-to sftp has its own SFTP client and doesn't read ~/.ssh/config the way the system ssh/scp binaries do — so an alias set up via wg-easy's sync-ssh-aliases.sh (or any ~/.ssh/config Host entry) worked fine for the DR-spare connectivity check (which shells out to real ssh) but silently failed for this mirror: a plain @-split on an alias like "main" (no @ present) produced --host=main, a name that only resolves inside ~/.ssh/config, not real DNS. The dry-run check correctly rejected it and the mirror was never saved — no error surfaced beyond that, so it looked like nothing happened. Now resolves the destination through `ssh -G` before building the Kopia flags — the same mechanism ssh itself uses to expand config aliases — and falls back to the previous plain @-split only if that comes back empty. Verified against three cases: a bare alias (resolves via a mock ~/.ssh/config Host block), an explicit user@ip (passes through unchanged), and an unrecognized name (falls back to a sane literal hostname rather than erroring). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn --- services/backup.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/services/backup.sh b/services/backup.sh index eca1d5f..8509147 100644 --- a/services/backup.sh +++ b/services/backup.sh @@ -770,11 +770,25 @@ install_backup() { prompt_yn " Add a direct SFTP mirror to another box$( [ -n "$_sftp_default_host" ] && echo " (e.g. $_sftp_default_host, same as the DR-spare above)")? (y/n):" "n" _ADD_SFTP_MIRROR if [[ "$_ADD_SFTP_MIRROR" =~ ^[Yy]$ ]]; then local _SFTP_DEST="" - prompt_text " SSH destination, user@host:" "$_sftp_default_host" _SFTP_DEST + prompt_text " SSH destination, user@host (~/.ssh/config aliases work too):" "$_sftp_default_host" _SFTP_DEST if [ -z "$_SFTP_DEST" ]; then log_warning " No destination entered — skipping this mirror." else - local _SFTP_USER="${_SFTP_DEST%%@*}" _SFTP_HOSTNAME="${_SFTP_DEST#*@}" + # Resolve through `ssh -G` rather than a plain @-split, so an + # ~/.ssh/config alias (e.g. from wg-easy's sync-ssh-aliases.sh) + # works here too. Kopia's sync-to sftp has its own SFTP client + # and does not read ~/.ssh/config itself — --host has to be the + # real hostname/IP either way, so this resolves it once here + # instead of failing later with the alias name as a literal, + # unresolvable hostname. Falls back to the plain @-split if + # `ssh -G` can't resolve it (e.g. no matching Host block). + local _ssh_g _SFTP_USER _SFTP_HOSTNAME + _ssh_g="$(ssh -G "$_SFTP_DEST" 2>/dev/null)" + _SFTP_USER="$(echo "$_ssh_g" | awk '/^user /{print $2; exit}')" + _SFTP_HOSTNAME="$(echo "$_ssh_g" | awk '/^hostname /{print $2; exit}')" + [ -z "$_SFTP_USER" ] && _SFTP_USER="${_SFTP_DEST%%@*}" + [ -z "$_SFTP_HOSTNAME" ] && _SFTP_HOSTNAME="${_SFTP_DEST#*@}" + log_info " Using ${_SFTP_USER}@${_SFTP_HOSTNAME} for this mirror (resolved via ~/.ssh/config)." local _SFTP_PATH="" _MIRROR_NAME="" prompt_text " Remote path for the repo:" "~/backups/kopia-mirror" _SFTP_PATH _SFTP_PATH="${_SFTP_PATH:-~/backups/kopia-mirror}"