Score:2

script using rsync by SSH encounters 'Host key verification failed' but only when ran by systemd service

hn flag

I am running an rsync script to copy files from a pi to local folder, the script works as intended when run manually but fails with:

: Host key verification failed.
: rsync error: unexplained error (code 255) at rsync.c(703) [Receiver=3.2.3]

When run by a service file, would appreciate any help on where I am going wrong.

script:

#!/bin/bash

experimentNum=$(sshpass -p 'pass' ssh user@IP "cat /source/source.txt")

mkdir -p /dest/$experimentNum

sshpass -p 'pass' rsync -zaP user@IP:/source/ /dest

sshpass -p 'pass' ssh user@IP sudo find /source/ -mtime +14 -daystart -delete

Service:

[Unit]
Description=backup
StartLimitIntervalSec=0

[Service]
Type=oneshot
ExecStart=/usr/bin/bash /absolute-path/drive_backup.sh
Restart=on-failure
RestartSec=5
Score:2
hn flag

Right so fairly simple fix and something that I overlooked was running the service for the user (with User=user under the [service] sub-heading) that created the ssh key not remembering that they are specific to a user!

[Unit]
Description=backup
StartLimitIntervalSec=0

[Service]
Type=oneshot
ExecStart=/usr/bin/bash /absolute-path/drive_backup.sh
Restart=on-failure
RestartSec=5
User=user
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.