Automation with systemd failing to connect over ssh #340
Labels
No Label
bug
data loss
design finalized
good first issue
new feature area
question / support
security
waiting for response
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: borgmatic-collective/borgmatic#340
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
Automatic borgmatic backups using systemd service
Steps to reproduce (if a bug)
Contents of /etc/systemd/system/borgmatic.service
Contents of /etc/borgmatic.d/work.yaml
I have
~/.ssh/id_rsa.pub
inbbb@ccc.rsync.net:.ssh/authorized_keys
, and can successfullyssh bbb@ccc.rsync.net
from the terminal.Actual behavior (if a bug)
When I manually run
borgmatic --verbosity 1 --files
it is successful. However, when I runsystemctl start borgmatic.service
I get an error:Expected behavior (if a bug)
borgmatic should be able to ssh into rsync.net when run from systemd.
Environment
borgmatic version: [version here]
1.5.8
borgmatic installation method:
pip install borgmatic (within the base conda environment)
Borg version: [version here]
1.1.5
Python version: [version here]
3.8.2
operating system and version:
Ubuntu 18.04
The problem is likely that you've run borgmatic from a different user account than it's running with under systemd (root) and the root user doesn't have the remote server's host key yet.
To resolve this:
SSH into the remote server once as root. You'll probably get a prompt like this:
Type yes to add the host key to
/root/.ssh/known_hosts
.You could also
ssh_keyscan ccc.rsync.net >> /etc/ssh/ssh_known_hosts
to add the host key to the global SSH configuration.Thanks,
I ran
sudo ssh ...
and added the host key, but borgmatic still does not successfully ssh, givingI assume the problem is that root is not using my local user's
/home/myuser/.ssh/id_rsa
keypair.Aha, I just saw the config option
which resolves this issue.
It then raised a new issue, specific to rsync.net, which by defualt uses borg 0.29.0. I had previously set
export BORG_REMOTE_PATH=/usr/local/bin/borg1/borg1
in my .bashrc, but systemd and root do not load this (conversly,export BORG_RSH="ssh -i /home/myuser/.ssh/id_rsa"
likewise does not work). To overcome this, I just set the configWith these two changes, borgmatic.service works for me as expected. Thanks for your help!