Running lsyncd on Ubuntu 16.04 and 18.04

Akitogo Team, 08 Mar 2018

This is a quick technical note for running lsyncd on Ubuntu 16.04 and 18.04. Assuming that you have installed lsyncd successfully as a service and you want to sync files which have root read only permission to another Ubuntu server. If you don't have proper access to the destination server you might find in your lsyncd.log something like 

rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]
Thu Mar  8 10:54:47 2018 Error: Temporary or permanent failure on startup of "/etc/blabla/". Terminating since "insist" is not set.
Thu Mar  8 10:58:21 2018 Normal: recursive startup rsync: /etc/blabla/ -> x.x.x.:/etc/blabla/
Host key verification failed.

Here are the steps you have to take:

 

  • On source server, change to root using 
    sudo -i
    

    Generate ssh keys using 

    ssh-keygen -t rsa
    
  • On destination server, make sure that root login is enabled, instructions can be found here: How to enable ssh root access ubuntu 16.04
  • On source server, now copy ssh key to destination server using
    ssh-copy-id -i ~/.ssh/id_rsa.pub root@DestinationServer
    
  • On destination server you might want to disable again password login for root. 
    sudo vi /etc/ssh/sshd_config
    
    Change:
    PasswordAuthentication no
    PermitRootLogin without-password
    
    Save changes and
    sudo service ssh restart
    
  • Finally restart lsyncd

 

You might see another error in your logs;

Tue Jun 30 16:07:01 2020 Error: Terminating since out of inotify watches.
Consider increasing /proc/sys/fs/inotify/max_user_watches

Listen uses inotify by default on Linux to monitor directories for changes. If you have a high number of files to monitor. Ubuntu's default inotify limit is set to 8192. You can adjust the value permanently to a higher value if you run this command:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p