ssh does not work when called from systemd
Solution 1:
debug1: read_passphrase: can't open /dev/tty: No such device or address
The log says that your private key is encrypted and the client can't use it before you will enter a passphrase. Either use unencrypted key or use again some dirty workaround using sshpass
.
Solution 2:
debug1: read_passphrase: can't open /dev/tty: No such device or address
The log says that your private key is encrypted and the client can't use it before you will enter a passphrase. And as you say in your comment:
The key is automatically unlocked when I log in but apparently not for systemd
To ensure this is done, you need to execute the script as if you logged in with your login name.
[Unit]
Description=sync Bilder to nas
[Service]
User=<YOUR USER NAME>
WorkingDirectory=/home/<YOUR USER NAME>
ExecStart=bash -l -c "/home/tikey/scripts/nas_sync_photos_to_nas.sh"
from man bash
:
-c string If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $0.
-l Make bash act as if it had been invoked as a login shell (see
INVOCATION below).
from man systemd.exec
:
User=, Group= Set the UNIX user or group that the processes are executed as,
respectively. Takes a single user or group name, or a numeric
ID as argument. etc...