6

I have a private virtual server to which I'm trying backup some directories from local my /home directory.

I've prepared this script:

#!/bin/bash

/usr/bin/rsync -rvvv /home/arkadiusz/scripts [email protected]:/home/backup/

/usr/bin/notify-send "Backup complete" "~/scripts -> vps" -i cryptkeeper

In user's crontab I've added entry:

*/1 * * * * /home/arkadiusz/scripts/vps.sh > /home/arkadiusz/cron-vps.log 2> /home/arkadiusz/cron-vps.error.log

After executing the shell script, my scripts directory doesn't appear in /home/backup/ on the remote server. In cron-vps.log file I see only this:

opening connection using: ssh -l root XXX.XXX.26.106 rsync --server -vvvre.iLsfx . /home/backup/  (9 args)
[sender] _exit_cleanup(code=12, file=io.c, line=226): about to call exit(255)

In cron-vps.error.log file turns out that this is an authorization problem:

Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]

I've checked additionally sshd status on my remote server:

root@vpsXXXXXX:/home/backup# service sshd status
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2017-04-12 01:04:09 CEST; 12h ago
 Main PID: 281 (sshd)
   CGroup: /system.slice/ssh.service
           └─281 /usr/sbin/sshd -D

...

Apr 12 13:41:01 vpsXXXXXX.ovh.net sshd[5019]: Failed password for root from XXX.XXX.232.122 port 21782 ssh2
Apr 12 13:41:01 vpsXXXXXX.ovh.net sshd[5019]: Failed password for root from XXX.XXX.232.122 port 21782 ssh2
Apr 12 13:41:01 vpsXXXXXX.ovh.net sshd[5019]: Connection closed by XXX.XXX.232.122 port 21782 [preauth]

Based on these logs, it seems to be a problem with authorization, but my SSH connection works when I try to log in to my remote sever with this command:

ssh [email protected]

Also, the rsync command works in terminal without any passwords:

/usr/bin/rsync -rvvv /home/arkadiusz/scripts [email protected]:/home/backup/

What am I doing wrong?

12
  • try with sudo on cron file Apr 12, 2017 at 11:56
  • @Ravi, unfortunatelly it doesn't work. Logs: cron-vps.log: opening connection using: ssh -l root 5.196.26.106 rsync --server -vvvre.iLsfx . /home/backup/ (9 args) [sender] _exit_cleanup(code=12, file=io.c, line=226): about to call exit(255) cron-vps.error.log: grep: /proc//environ: No such file or directory Host key verification failed. rsync: connection unexpectedly closed (0 bytes received so far) [sender] rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1] Apr 12, 2017 at 12:02
  • First try to run script manually and let me know Apr 12, 2017 at 12:05
  • Manually works perfectly, both script and one-line command in terminal. Apr 12, 2017 at 12:07
  • Have you try this way rsync -v -v -e '/usr/bin/ssh -p YY' ./testfile me@XXXXX:/home ? Apr 12, 2017 at 12:22

1 Answer 1

4

In cron-vps.error.log file turns out that this is an authorization problem:

The authentication and authorization is a different problem. This is authentication, which fails (in this case the password, as visible from the logs).

Most probably you have set up your private key to be encrypted, but you do not notice it it normal sessions, because you have got it stored in the ssh-agent. It works fine in your session, but that won't work in the session that is initiated from your crontab.

3
  • What can I do to get it working? If I understand correctly it's a problem with my private key. Is it depends on access to file by permissions and cron has no access to this? Apr 12, 2017 at 13:04
  • 1
    Verify if your key has a passphrase/is encrypted. If so, either remote the passphrase or generate separate key in different location used for your rsync and make sure you can connect with it ( use switches -oIdentityFile=/path/to/key -oIdentitiesOnly=yes).
    – Jakuje
    Apr 12, 2017 at 13:08
  • Thanks @Jakuje and @Ravi I've used key without passphrase and works great under cron: /usr/bin/rsync -rvvv -e "ssh -i $HOME/.ssh/backup-key" /home/arkadiusz/scripts [email protected]:/home/backup/ Apr 12, 2017 at 13:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .