Ubuntu – Ubuntu 16.04 rsync via ssh prompts me for password, how to make it a cron job

rsyncssh

Ubuntu 16.04 How to install rsync server for other systems to access via ssh using cron

Setup: system "prime" with Ubuntu 16.04 and a second hard drive just for backups.

/dev/sdb1 is mounted at /mnt via using blkid to get the uuid then adding a line to /etc/fstab

I created a subdirectory named /mnt/full/prime for the first backup, of the prime boot SSD contents.

–> Running the command:

sudo rsync -aAXv / --delete --ignore-errors --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /mnt/full/prime

does indeed make a nice mirror copy of the root file system into that directory /mnt/full/prime

It is totally cool – like Robocopy with the /MIR option – it only transfers changes so runs a lot faster after the files have been copied the first time.


Now, to set it up for others to access, I found this article

How to Use rsync to Backup Your Data on Linux

It says to run the following command:

sudo apt-get install ssh rsync

it installed normally.
–EDIT: This turns out to be unnecesary. –END EDIT–

All of my systems have the passwordless login set up in both directions.

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub <target-system>

and I have no problem with passwordless scp copies and ssh.

So I then created a subdirectory under mnt/full for my next system "solar" – /mnt/full/solar and using ssh into the Raspbian system "solar" I issued the same rsync command but with the target directory being pi@prime:/mnt/full/solar

mkdir /mnt/full/solar
ssh solar
sudo rsync -aAXv / --delete --ignore-errors --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} pi@prime:/mnt/full/solar

but it prompted me for the password to pi@prime – rsync does not respect the normal passwordless login setup.

Once I entered the password the copy proceeded normally.

So now all seems well except this won't work as a daily cron job if it is going to prompt for a password.

The question is in the title: Ubuntu 16.04 rsync via ssh prompts me for password, how to make it a cron job?

Best Answer

This should do it:

sudo rsync -e 'ssh -i /path/to/pi's/id_rsa' -aAXv / --delete --ignore-errors --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/m‌​nt/*","/media/*","/l‌​ost+found"} pi@prime:/mnt/solar