I have three questions from the use of one rsync command, below:

sudo rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress <user>@<ip.address>:~/public_html/ /var/www/html

1.) How can change this command so that I can use it without passwords? I want to automate periodic uploads/downloads from my server with a cronjob. As is, I need to enter my local user pwd because the html folder is within the file system. Secondly, even though I have setup a ssh key with the remote host and I can establish a connection without entering my remote host password, this command prompts me enter the remote host pwd again (not recognizing saved ssh keys)

2.) Prior to using the above rsync command, my LAMP dev environment worked fine. However, after downloading my sites from the remote host via the above command, the permissions to files & directories changed. I believe the -a attribute maintained the remote host's username & permissions. How do I get my LAMP permissions back to what they were?

I already ran 'sudo chown -R www-data:www-data /var/www/html', however, my wordpress sites now all redirect to the live production sites, example: https://localhost.sitename.org redirects to https://sitename.org/wp-signup.php?new=localhost

No, the /etc/hosts has not been edited and is set-up perfectly.

3.) What attributes should I use with the above rsync command as to avoid my current quagmire in the future? SSH w. RSYNC is clearly faster and more secure than any ftp. Just need help refining my usage of it. thanks.

1 Answer 1

  1. Put this in your cron (to do it daily at 3:12)
12 3 * * * root rsync -Havz USEROFTHESOURCEHOST@SOURCEHOST:~/public_html/ /var/www/html/

sudo is not necessary because we already use root to provide the correct permission.
Make sure you have ssh keys for root (and not only your regular user)
Also, don't forget the trailing / at the end

  1. -adoes indeed keep most properties of all files. But keep in mind that the same user can have different UID's and GID's on different systems. The "real" property is the UID (and GID) and not the username (or groupname)

  2. The command I placed above is actually not what i would do in real live, i would use the cron on the source instead of the destination host so that it becomes:

12 3 * * * root rsync -Havz /home/USEROFTHESOURCEHOST/public_html/ USERATTHEDESTHOST@DESTINATIONHOST:/var/www/html/

(Make sure that your USERATTHEDESTHOST is a user that has permission to write in /var/www/html)

You must log in to answer this question.

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