CT 114: restic sftp.command mit explizitem Key/known_hosts
ci-static / secret-scan (push) Successful in 21s
ci-static / yamllint (push) Successful in 30s
ci-static / ansible-syntax (push) Successful in 32s
ci-static / markdown-links (push) Successful in 22s

ssh loest ~ aus dem passwd-Eintrag, nicht aus $HOME — HOME=/etc/litecoin-backup
griff nicht. Backup-Skript und restic-check übergeben Key und known_hosts
jetzt per -o sftp.command an restic (BatchMode, StrictHostKeyChecking).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-27 07:17:52 +01:00
parent b713be5e2f
commit 21e410e8cd
3 changed files with 9 additions and 4 deletions
@@ -5,7 +5,6 @@ Description=Monthly restic check of the Litecoin wallet backup repository
Type=oneshot
Environment=RESTIC_REPOSITORY={{ litecoin_backup_repository }}
Environment=RESTIC_PASSWORD_FILE={{ litecoin_backup_password_file }}
Environment=HOME={{ litecoin_backup_env_dir }}
Environment=SSH_AUTH_SOCK=
ExecStart=/usr/bin/restic check --read-data-subset=5%
ExecStart=/usr/bin/restic -o sftp.command="ssh -i {{ litecoin_backup_ssh_key }} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile={{ litecoin_backup_known_hosts }}" check --read-data-subset=5%
Nice=10
@@ -5,7 +5,7 @@ After=litecoind.service
[Service]
Type=oneshot
ExecStart={{ litecoin_backup_script }}
# SSH key for the restic sftp target, root-only.
Environment=HOME={{ litecoin_backup_env_dir }}
# Runs as root; the script passes the restic SSH key and known_hosts
# explicitly via restic's sftp.command (ssh ignores $HOME for ~).
Environment=SSH_AUTH_SOCK=
Nice=10
@@ -10,6 +10,10 @@ set -Eeuo pipefail
export RESTIC_REPOSITORY="{{ litecoin_backup_repository }}"
export RESTIC_PASSWORD_FILE="{{ litecoin_backup_password_file }}"
# ssh resolves ~ from the passwd entry, not from $HOME, so the restic sftp
# backend gets the key and known_hosts explicitly via sftp.command.
SFTP_COMMAND="ssh -i {{ litecoin_backup_ssh_key }} -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=yes -o UserKnownHostsFile={{ litecoin_backup_known_hosts }}"
backup_dir="{{ litecoin_backup_wallet_dir }}"
today="$(date +%F)"
@@ -18,9 +22,11 @@ today="$(date +%F)"
backupwallet "${backup_dir}/wallet-${today}"
/usr/bin/restic -r "$RESTIC_REPOSITORY" \
-o "sftp.command=$SFTP_COMMAND" \
--password-file "$RESTIC_PASSWORD_FILE" \
backup "$backup_dir"
/usr/bin/restic -r "$RESTIC_REPOSITORY" \
-o "sftp.command=$SFTP_COMMAND" \
--password-file "$RESTIC_PASSWORD_FILE" \
forget --keep-daily {{ litecoin_backup_keep_daily }} --prune