I'm having issues transferring files with rsync via ssh. If I just run
rsync -avz devel@10.10.10.83:/home/devel/ $/home/user/rsync/servidor
it works as expected since the public key is stored in the remote computer, but if I run this same line on crontab,
* * * * * rsync -avz devel@10.10.10.83:/home/devel/ $HOME/rsync/servidor
the synchronization fails.
After browsing the web, I came across that crontab is not able to see the private key since it runs with some restrictions, so I changed crontab to the following
* * * * * cd /home/user/rsync;/bin/sh transfer.sh >> /home/user/rsync/log/cron.log 2>&1
where the transfer.sh is
#!/bin/sh
#BASH_ENV=/home/user/.bashrc
echo ""
echo "Cronjob started for back-up files" `date`
set -xv
/usr/bin/rsync -avz -e "/usr/bin/ssh -i $/home/user/.ssh/id_rsa" devel@10.10.10.83:/home/devel/ /home/user/rsync/servidor
The idea is that now rsync explicitly use ssh private key to connect to the remote machine, but I still have problems with this approach though. The log:
Cronjob started for back-up files Qua Fev 4 13:39:02 BRST 2015
#/usr/bin/rsync -vv devel@10.10.10.83:/home/devel /home/user/rsync/servidor
#rsync -avz -e “ssh -i /home/user/.ssh/id_rsa” devel@10.10.10.83:/home/devel /home/user/rsync/servidor
/usr/bin/rsync -avz -e "/usr/bin/ssh -i $HOME/.ssh/id_rsa" devel@10.10.10.83:/home/devel/ $HOME/rsync/servidor
+ /usr/bin/rsync -avz -e /usr/bin/ssh -i /home/user/.ssh/id_rsa devel@10.10.10.83:/home/devel/ /home/user/rsync/servidor
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(226) [Receiver=3.1.0]
However, the line
/usr/bin/rsync -avz -e "/usr/bin/ssh -i $/home/user/.ssh/id_rsa" devel@10.10.10.83:/home/devel/ /home/user/rsync/servidor
runs ok from the terminal.
OS: Linux mint Quaina
Any help would be appreciated
EDIT: I used a passphrase when I created the SSH key. The permissions are:
ls -l /home/user/.ssh/id_rsa
-rw------- 1 user user 1766 Dez 16 15:40 /home/user/.ssh/id_rsa
/home/user/.ssh/id_rsa
protected with a passphrase?