Using rsync in a cronjob when a password is needed
This is the command I use to backup to another machine:
rsync -av -e "ssh -i /root/ssh-rsync-valhalla-key" \
--exclude lost+found \
--delete-before \
/mnt/backup/ \
[email protected]:/cygdrive/r/\!Backups/Niflheim &
So you can use the -i
to pass a keyfile to ssh. Of course, in your example, that means the keyfile itself will be sharable via HTTP if anybody ever figures out the filename.
Related videos on Youtube

Comments
-
NobbZ 4 months
Basically I have a bash script that fetches data from my server to perform a backup.
As it is now I have to start that script manually, enter the password, and then wait for it to finish.
I would like to set up a cronjob that handles the backup.
But I really don't know how to handle the password in a cronjob.
Also I can't use keys for this, because my provider does not provide the mechanisms I need to configure them.
I have SSH access to my home folder, but in my home folder I don't have write access except for the
http(s)docs
directory. So I can't create the necessary~/.ssh/
directory and its contents for login via keys. -
NobbZ about 11 yearsSo the path in the ssh command would be the path to the keyfiles on the remote? Since I dont use https on the server and it is deactivated I could then throw my keyfiles into httpsdocs and they would be safe there. I will give that a try in the evening.
-
Caesium about 11 yearsNo, the -i path is a local path. So he means run this in reverse; initiate the rsync from your server back to your home PC; 192.168.1.99 would be your IP.
-
Aaron D. Marasco about 11 yearsWhat @Caesium said - this command pushes. You need to have
sshd
running on your home machine (along with firewall port forwarding, etc, etc). In my example, it pushes everything in/mnt/backup/
toR:\!Backups\Niflheim
on a Windows/Cygwin box @192.168.1.99. -
Aaron D. Marasco about 11 yearsThe key file that
-i
specifies is the private key file... starts with-----BEGIN DSA PRIVATE KEY-----