LINUX, FOSS AND LIBRARY TECHNOLOGY ENTHUSIAST

Thursday, March 27, 2025

Synchronizing Files with Unison on Debian/Ubuntu

0 comments
Unison is a powerful, open-source file synchronization tool that allows you to keep files and directories consistent across multiple machines. It works efficiently over SSH and is a great alternative to tools like rsync when two-way synchronization is required.

Installing Unison on Debian/Ubuntu

To install Unison, run the following command:

sudo apt update && sudo apt install unison

If you plan to synchronize files over SSH, ensure OpenSSH is installed as well:

sudo apt install openssh-client openssh-server

Setting Up Password-less SSH for Automation

To avoid entering a password every time Unison runs, set up SSH key authentication:

Generate an SSH Key (if you haven’t already):

ssh-keygen -t rsa -b 4096

  • Press Enter to save it in the default location (~/.ssh/id_rsa).
  • If prompted, enter a passphrase (or leave it blank for no passphrase).

Copy the SSH Key to the Remote Server:

ssh-copy-id mahesh@192.168.1.125

  • Enter the password once to install the key.

Verify Password-less SSH Login:

ssh mahesh@192.168.1.125

  • You should log in without being asked for a password.

Basic Usage

1. Synchronizing Local Directories

To synchronize two local directories, use:

unison /path/to/source /path/to/destination

unison /home/koha/Dropbox /home/koha/Dcouments

Unison will analyze the differences and prompt you to confirm each action.

2. Synchronizing Over SSH

To sync directories between a local and a remote machine:

unison /home/koha/Dropbox ssh://mahesh@192.168.1.125///home/mahesh/Documents

Replace mahesh@192.168.1.125 with your actual remote server credentials.

3. Using a Profile for Automation

To simplify usage, create a profile in ~/.unison/default.prf:

sudo nano ~/.unison/default.prf

root = /home/koha/Dropbox
root = ssh://mahesh@192.168.1.125///home/mahesh/Documents

auto=true
batch=true

Then run:

unison default

This enables automatic sync without manual confirmation.

Unison is an excellent tool for bidirectional synchronization, providing flexibility and control over file updates. Whether for backups, team collaboration, or server mirroring, it ensures consistency across systems with minimal effort.

No comments:

Post a Comment