Estou tentando escrever um script para rsync uma pasta no meu laptop para o meu NAS. O script é executado corretamente quando chamado na linha de comando. Eu tentei configurar o script para ser executado automaticamente com o systemd. No entanto, há um problema com o login do ssh. Enquanto funciona bem quando o script é executado a partir da linha de comando, recebo um erro de permissão negada.
Eis o que tentei até agora para limitar o problema:
O 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
Para executar o script com o systemd, eu coloquei o arquivo sync-photos-to-nas.service
em ~/.config/systemd/user/
:
[Unit]
Description=sync Bilder to nas
[Service]
ExecStart=/home/tikey/scripts/nas_sync_photos_to_nas.sh
A execução do script a partir da linha de comando funciona bem. Infelizmente, executar o script com o systemd não funciona. Eu executei o serviço systemd com systemctl --user start sync-photos-to-nas.service
. Então, usando journalctl --user-unit sync-photos-to-nas
, obtenho:
...
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'.
Alguém sabe qual é o problema?