How to RSYNC with remote server using certificates

This was a task I had to do in order to have Drupal working better behind a load balancer. Anyhow, it can be used in a number of ways, I’ll let it to your imagination and use cases.

Install RSYNC

To install RSYNC on Ubuntu systems:

sudo apt install rsync

rsync specific case KB

These are some articles I read in order to understand how to connect to another server to sync folders:

Rsync absolute paths:

https://unix.stackexchange.com/questions/174674/rsync-a-list-of-directories-with-absolute-path-in-text-file/197196

rsync -a --relative /home/bcntest/public_html/web/sites/default/files

The rsync command with all the parameters

A brief description of the command:

  • it connects using a certificate
  • it executes the local AND remote command with sudo
  • executes the ssh connection quietly (-q)
  • syncs the ‘files/’ (don’t forget to put the “/” at the end of the path) folder from instance 1 to instance 2
sudo rsync -Pav -e "ssh -q -i /home/user/.ssh/privatekey_private.pem" --rsync-path="sudo rsync" /home/user/public_html/web/sites/default/files/ ubuntu@10.0.1.3:/home/user/public_html/web/sites/default/files/
sudo rsync -Pav -e "ssh -q -i /home/user/.ssh/privatekey_private.pem" --rsync-path="sudo rsync" /home/user/public_html/private_files/webform/ ubuntu@10.0.1.3:/home/user/public_html/private_files/webform/

Below is the SSH command alone, you can use it to test if the connection is working:

ssh -q -f -i /home/user/.ssh/privatekey_private.pem ubuntu@10.0.1.3 -tt
ssh -i /home/user/.ssh/privatekey_private.pem ubuntu@10.0.1.38 -tt

Some extra content

I tried to enable certificate logins with webmin and usermin to no success, if anyone knows how to do it please leave a comment.

SSH via webmin: http://doxfer.webmin.com/Webmin/SSH_Server

Posted in Server management, Web Development and tagged , , , , , .

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.