I am trying to write a script to rsync a folder on my laptop to my NAS. The script runs fine when called from the commandline. I've tried setting up the script to run automatically with systemd. However, there is a problem with the ssh login. While it works fine when the script is run from the commandline, I get a permission denied error.
Here is what I've tried so far to narrow down the problem:
The script /home/tikey/scripts/nas_sync_photos_to_nas.sh
:
#!/bin/bash
set -x
ssh [email protected] -v -i /home/tikey/.ssh/id_rsa ls -la rsync_laptop
To run the script with systemd, I've put the file sync-photos-to-nas.service
in ~/.config/systemd/user/
:
[Unit] Description=sync Bilder to nas [Service] ExecStart=/home/tikey/scripts/nas_sync_photos_to_nas.sh
Running the script from the commandline works fine. Unfortunately, running the script with systemd does not work. I've run the systemd service with systemctl --user start sync-photos-to-nas.service
. Then, using journalctl --user-unit sync-photos-to-nas
, I get:
... debug1: Host '192.168.17.200' is known and matches the RSA host key. debug1: Found key in /home/tikey/.ssh/known_hosts:2 debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: publickey debug1: Offering RSA public key: /home/tikey/.ssh/id_rsa debug1: Server accepts key: pkalg ssh-rsa blen 535 debug1: read_passphrase: can't open /dev/tty: No such device or address debug1: Next authentication method: keyboard-interactive debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: Next authentication method: password debug1: read_passphrase: can't open /dev/tty: No such device or address debug1: Authentications that can continue: publickey,password,keyboard-interactive Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or address debug1: Authentications that can continue: publickey,password,keyboard-interactive Permission denied, please try again. debug1: read_passphrase: can't open /dev/tty: No such device or address debug1: Authentications that can continue: publickey,password,keyboard-interactive debug1: No more authentication methods to try. sync-photos-to-nas.service: Main process exited, code=exited, status=255/n/a sync-photos-to-nas.service: Unit entered failed state. sync-photos-to-nas.service: Failed with result 'exit-code'.
Does anybody know what the problem might be?