Saya mencoba menulis skrip untuk me-rsync folder di laptop saya ke NAS saya. Script berjalan dengan baik ketika dipanggil dari commandline. Saya sudah mencoba mengatur skrip untuk berjalan secara otomatis dengan systemd. Namun, ada masalah dengan login ssh. Sementara itu berfungsi dengan baik ketika skrip dijalankan dari commandline, saya mendapatkan izin ditolak kesalahan.
Inilah yang saya coba sejauh ini untuk mempersempit masalahnya:
Naskah /home/tikey/scripts/nas_sync_photos_to_nas.sh
:
#!/bin/bash
set -x
ssh tikey@192.168.17.200 -v -i /home/tikey/.ssh/id_rsa ls -la rsync_laptop
Untuk menjalankan skrip dengan systemd, saya telah meletakkan file sync-photos-to-nas.service
di ~/.config/systemd/user/
:
[Unit] Description=sync Bilder to nas [Service] ExecStart=/home/tikey/scripts/nas_sync_photos_to_nas.sh
Menjalankan skrip dari baris perintah berfungsi dengan baik. Sayangnya, menjalankan skrip dengan systemd tidak berfungsi. Saya sudah menjalankan layanan systemd dengan systemctl --user start sync-photos-to-nas.service
. Lalu, gunakan journalctl --user-unit sync-photos-to-nas
, Saya mendapat:
... 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'.
Adakah yang tahu apa masalahnya?