Set up BitTorrent Sync on your Linux Server

With the general availability of BitTorrent Sync 2.0 recently announced, we see introduction of many Pro features for their service. I played around with the platform when it was still in the early stages and has it come a long way. Not only is it aesthetically pleasing but the fine grain controls that can be set when sharing files are welcomed as well.

BTSync works great locally and on the cloud as well, especially after losing storage on Dropbox with the Space Race bonus now expired (you probably got that email!). This is definitely worth a look if you want to roll your own cloud storage with no limits.

So assuming you have some Terminal command line-fu know-how, get the appropriate binary here then extract its contents with tar. Before you run the btsync executable, run ./btsync --dump-sample-config first to get a copy of the default configuration. It should look something like this:

  "device_name": "Device Name",
  "listening_port" : 0, // 0 - randomize port

/* storage_path dir contains auxilliary app files if no storage_path field: .sync dir created in the directory
   where binary is located. otherwise user-defined directory will be used */
 "storage_path" : "/var/lib/btsync",

/* set location of pid file */
// "pid_file" : "/var/run/btsync/",

/* use UPnP for port mapping */
  "use_upnp" : false,

/* limits in kB/s. 0 - no limit */
  "download_limit" : 0,
  "upload_limit" : 0,

/* proxy configuration */
// Removed for conciseness

  "webui" :
    "listen" : "" // remove field to disable WebUI

/* preset credentials. Use password or password_hash */
  ,"login" : "btsync"
//  ,"password" : "password"
  ,"password_hash" : "obfuscated" // password hash in crypt(3) format
//  ,allow_empty_password" : false // Defaults to true
/* ssl configuration */
//  ,"force_https" : true // disable http
//  ,"ssl_certificate" : "/path/to/certificate.pem"
//  ,"ssl_private_key" : "/path/to/private.key"

/* directory_root path defines where the WebUI Folder browser starts (linux only). Default value is / */
//  ,"directory_root" : "/media/misc/backups"

/* dir_whitelist defines which directories can be shown to user or have folders added (linux only)
   relative paths are relative to directory_root setting */
//  ,"dir_whitelist" : [ "/home/user/MySharedFolders/personal", "work" ]

/* !!! if you set shared folders in config file WebUI will be DISABLED !!!
   shared directories specified in config file  override the folders previously added from WebUI. */

// 'shared folders' block removed for conciseness


What you should set are the credential if you're going to be accessing the web UI remotely. You should also consider entering some speed limits as well to respect any rules put in place by your host.

Once you're satisfied with your configuration you can run it by invoking ./btsync --config btsync.config. You can then visit YOUR_IP:8888 on your browser and login with the set credentials. Note that every time you start the process with the config file, your Preferences from the web UI will be replaced with the values in the file instead.

BONUS: Make BTSync a service that runs on startup

It would probably be convenient if BTSync was up and running again in the case of a server reboot. This can be achieved by creating a simple script in init.d:

#! /bin/sh
# /etc/init.d/btsync
# Carry out specific functions when asked to by the system
case "$1" in
    /PATH_TO/.btsync/btsync --config /PATH_TO/.btsync/btsync.config
    killall btsync
    echo "Usage: /etc/init.d/btsync {start|stop}"
    exit 1
exit 0

Then change the permissions by running chmod 755 /etc/init.d/btsync and allow it to run on boot update-rc.d btsync defaults. To start the service enter service btsync start.

Vincent Seow

Vincent Seow