How To Synchronize Directories using Syncthing on Ubuntu 16.04

January 24, 2017 | By in OPEN SOURCE TOOLS
| Reply More

Syncthing replaces proprietary sync and cloud services with something open, trustworthy and decentralized. Your data is your data alone and you deserve to choose where it is stored, if it is shared with some third party and how it's transmitted over the Internet.

There are two methods for installing Syncthing on Ubuntu 16.04. One method involves installing it using snapd tool. The other involves using the apt-get tool that auto-installs Syncthing on it.

In this tutorial, you'll learn how to install, configure and synchronize directories on Ubuntu 16.04.

Pre-requisites

To follow this tutorial, you will need the following:

64-bit Ubuntu 16.04 Droplet
Non-root user with sudo privileges

All the commands in this tutorial should be run as a non-root user. If root access is required for the command, it will be preceded by sudo.

Step 1 - Installing Syncthing

The Syncthing installation package available in the official Ubuntu 16.04 repository may not be the latest version. To get the latest and greatest version, install Syncthing from the official repository. This section shows you how to do just that.

But first, let's update the package database:

sudo apt-get update

The release channel is updated with full release builds, approximately once every two weeks.

Now let's install Syncthing. Add the PGP key for the official Syncthing repository to the system:

curl -s https://syncthing.net/release-key.txt | sudo apt-key add -

Add the "release" channel to your APT sources:

echo "deb https://apt.syncthing.net/ syncthing release" | sudo tee /etc/apt/sources.list.d/syncthing.list

Update the package database with the Syncthing packages from the newly added repo and install syncthing

sudo apt-get update
sudo apt-get install syncthing

Depending on your distribution, you may see an error similar to the following when running apt-get:

E: The method driver /usr/lib/apt/methods/https could not be found.

N: Is the package apt-transport-https installed?

E: Failed to fetch https://apt.syncthing.net/dists/syncthing/InRelease

If so, please install the apt-transport-https package and try again:

sudo apt-get install apt-transport-https

Alternatively

Syncthing can be installed using the snap tool.

sudo apt install snapd

snap install syncthing --candidate

Step 2 - Configuring Syncthing

With Syncthing installed and working, now's the time to become familiar with the command line utility. Using syncthing consists of passing it a chain of options and commands. Start it in whatever way you are most comfortable with; double-clicking should work in any graphical environment, but I’ll use the terminal to better illustrate what happens. At first start Syncthing will generate a configuration file, some keys and then start the admin GUI in your browser. Something like the following will be printed in the terminal:

$ syncthing

[monitor] 15:56:58 INFO: Starting syncthing 15:56:58 INFO: Generating RSA key and certificate for syncthing... [ANSMX] 15:57:05 INFO: syncthing v0.10.14 (go1.4 darwin-amd64 default) jb@syno... [ANSMX] 15:57:05 INFO: My ID: ANSMXYD-E6CF3JC-TCVPYGF-GXJPHSJ-MKUXBUQ-ZSPOKXH-... [ANSMX] 15:57:05 INFO: No config file; starting with empty defaults

At this point Syncthing will also have set up a folder called default for you, in a directory called Sync in your home directory. You can use this as a starting point, then remove it or add more folders later. The admin GUI starts automatically and remains available on https://localhost:8384/. Cookies are essential to the correct functioning of the GUI; please ensure your browser accepts them. It should look something like this:

For Syncthing to synchronize files with another device, it must be told about that device. This is accomplished by exchanging "device IDs". A device ID is a unique, cryptographically-secure identifier that is generated as part of the key generation the first time you start the tool. Two devices will only connect and talk to each other if they are both configured with each other’s device ID. Since the configuration must be mutual for a connection to happen, device IDs don’t need to be kept secret. They are essentially part of the public key.

To get your two devices to talk to each other click “Add Device” at the bottom right on both, and enter the device ID of the other side. You should also select the folder(s) that you want to share. The device name is optional and purely cosmetic. It can be changed later if required as shown below:

Once you click “Save” the new device will appear on right side of the GUI (although disconnected) and a prompt will be shown to indicate the need for a restart. Syncthing needs to be restarted for some configuration changes to take effect, such as sharing folders with new devices. When you click “Restart” Syncthing will first restart. and then connect to the new device after a minute or so. Remember to repeat this step for the other device(s).

At this point the two devices share an empty directory. Adding files to the shared directory on either device will synchronize those files to the other side. Each device scans for changes every 60 seconds, so changes can take a little over a minute to propagate to the other side, although some contributed wrappers include file system “watcher” features to speed this up. The rescan interval can be changed for each folder by clicking on a folder, clicking “Edit” and entering a new value for “Rescan Interval”.

Conclusion

There's a whole lot more to Syncthing than has been given in this article, but this should be enough to getting you started working with it on Ubuntu 16.04. There is more documentation and if you run into trouble feel free to post a question in the support forum. If you have problems getting devices to connect, first take a look at Firewall Setup, then look at any error messages in the GUI or on the console. Don’t forget that configuration changes will not be reflected instantly - give Syncthing a little time, especially after a restart.

Filed Under : OPEN SOURCE TOOLS, UBUNTU HOWTO

Tagged With : ,

Free Linux Ebook to Download

Leave a Reply

All comments are subject to moderation.