Prerequisites:
- One or more clients running a UNIX-like OS. Examples are given for Ubuntu 12.04 LTS, although all software components are available for other platforms as well (e.g. OS X). YMMV
- A cheap Ubuntu 12.04 VPS with storage. I recommend Backupsy, they offer 250GB storage for $5/month. Ask Google for coupon codes.
Software components used:
-
Install Unison:
$ sudo apt-get install unison
-
Add a user for our project and give him a decent password:
$ sudo adduser encbox
-
Install Unison:
$ sudo apt-get install unison
-
Enable key-based authentication for SSH (replace
your.vps.com
with your VPS' hostname):$ ssh-keygen $ cat ~/.ssh/id_rsa.pub | ssh encbox@your.vps.com "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
-
Create the folder holding our encrypted files:
$ mkdir ~/.encbox
-
Create a unison profile in
~/.unison/encbox.prf
(replaceyour.vps.com
with your VPS' hostname):$ mkdir ~/.unison; tee ~/.unison/encbox.prf <<__EOF root = /home/$USER/.encbox root = ssh://encbox@your.vps.com/encbox prefer = ssh://encbox@your.vps.com/encbox backups = true times = true terse = true repeat = 2 __EOF
-
Create an upstart file to start synchronization automatically (in
/etc/init/encbox.conf
):$ sudo tee /etc/init/encbox.conf <<__EOF description "encbox" start on desktop-session-start stop on desktop-shutdown setuid $USER setgid $USER env HOME=$HOME respawn script bash -l -c "unison encbox; sleep 2" end script __EOF
-
Start Unison:
# either run in foreground: $ unison encbox # or run it as a system service: $ sudo service encbox start # starts your Encbox $ sudo service encbox stop # stops your Encbox
If unison complains about archive files on your client, run it once with the
-ignorearchives
flag:$ unison -ignorearchives encbox
-
Install EncFS:
$ sudo apt-get install encfs
-
Mount encrypted directory:
$ encfs ~/.encbox ~/Encbox
Agree to have your target directory created, then choose
p
to use EncFS' preconfigured paranoia mode. Give your folder a decent password. -
That's it! All files in
~/Encbox
will be encrypted and synced securely between your VPS and all clients.
-
Polling:
Unfortunately, Unison doesn't support file system notifications (i.e. inotify, libnotify), so it polls your file system for changes every 2 seconds (if you set
repeat = 2
in your profile as we did above). This isn't nice, but I did not observe any negative effects on my notebook's battery life. Feel free to set therepeat
parameter to some higher value if you observe negative effects. Bandwith usage for polling is negligible as well (~0.9 kB/poll, ~3.5 kbit/s). -
Unison version
Rumor has it you should use the same Unison version on your server as well as on all your clients, or you will run into problems. I didn't test it, though.
-
Android / iOS app:
This setup is compatible with Boxcryptor Classic's smartphone apps. You just have to create an EncFS folder in expert mode (
x
) and follow the instructions at Boxcryptor's Support Desk. Then install a WebDAV server of your choice and expose/home/encbox/encbox
via WebDAV (not in this document's scope).
Perhaps is http://labs.bittorrent.com/experiments/sync.html an alternative protocol for this. There are clients for android, windows, mac and iphone(soon) available. And btsync seems to be at least open concept. I had a quick look on the data which is generated by it's network protocol. It syncs the files nearly in real time, but to do this, there is a need for much network traffic. The battery of your mobile phone will go down within hours. I do not know if this is caused by the protocol it self and cannot be changed or if this is a kind of bug, because the project is not that old.
What is realy nice about this idea is that there is no real master. But this leads to the problem of conflicts, if two devices lose the sync to the network and start to modify the same file at the same time. How to decide which change will survive.
My guess would be to have something like git oder mercurial to handle conflicts. But as a matter of fact, this is not compatible with non programming people. I'd like to have a solution which is able to handle the sync of a shopping list other at least 4 devices.
Are there libraries or tools which are able to merge changes on images, word documents and mp3s for example?
Multiple changes to images may be stored as layers, so a human can handle those conflicts. Word may be as simple as a source code. Mp3s are a little bit complicated to merge. In most use cases the sync of the meta data would be the solution, but if the file is cutted or normalized this change must be synced to all other devices in the sync network. If a mp3 get's corrupted, because the sd card in the mobile phone has an error, is an other problem. Because how can a simple sync tool can decide that this change has not to be synced.
@akbar501 owncloud is nice for contacts and calendar sync, but webdav is not a realy good protocol to sync files over multiple devices. There is no good way to handle conflicts.