I'm using rsync to backup directories on my local machine to a remote server. I have SSH key-based access set up and working for my user, so when I run the command:
rsync --update -razvP --progress ~/Projects/ ~/Documents/ [email protected]:backup/
Everything works as expected. So now I want to run that every day, so I pit it into a Bash script to be run via crontab:
~/backup1.sh
#!/usr/bin/env bash
rsync --update -razvP --progress ~/Projects/ ~/Documents/ [email protected]:backup/
$ ll ~/backup1.sh
-rwxr-xr-x 1 my-user admin 112B Nov 29 20:00 backup1.sh
$ crontab -e
30 15 * * * sh ~/backup1.sh
Unfortunately, when the cron job runs, it produces the following error:
Permission denied, please try again.
[email protected]: Permission denied (publickey,password).
I'm guessing crontab runs as its own user and thus is not finding my public key. IS there any way to tell either crontab or rsync to run as my user so that my public key is sent and authentication is successful?
crontab -u my-user -e
Command.crontab
normally operates on the crontab file belonging to user you run it as. So if you run it as my-user, it'll edit my-user's crontab file, and the listed jobs will run as my-user. Does access to the ssh keys depend on having an ssh-agent running?Permission denied
error.uname -a
Command. Thecrontab -u my-user -e
Command was just one of the suggestions that appears on the other Question. It seems that you have applied it. It also appears that the-u my-user
Switch is self-implied and therefore redundant. Since it has solved your Issue, then it must be one of the particularities of your own Version of the Operating System.