How to sync a shared folder from the local machine to another machine, via syncthing, on Mac, Linux & Windows

Syncing a shared folder from the local machine to another machine, even in a local Vagrant/VirtualBox setup, can be cumbersome in terms of slow I/O th...

Syncing a shared folder from the local machine to another machine, even in a local Vagrant/VirtualBox setup, can be cumbersome in terms of slow I/O throughput, especially when NFS fails to deliver or the shared folder's content is very big.

You have tried sshfs, rsync, Vagrant with NFS on etc., but none of them really gave you what you'd expect.. Well, it's 2016, wait no more .. syncthing to the rescue :)

Let's get started.

We will be using syncthing and syncthing-inotify to sync data from the Local Machine (LM) to the Remote Machine (RM).

The RM can be anything from a local VirtualBox VM instance, a docker container, a remote VPS or a bare metal server.

syncthing will sync on start and on each 60 sec, by default.

syncthing-inotify will check filesystem system events and in case of changes, will sync near real-time.

A. Mac64 LM & Linux64 RM

On the LM, install syncthing and syncthing-inotify

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-macosx-amd64-v0.14.10.tar.gz
$ tar -xvzf syncthing-macosx-amd64-v0.14.10.tar.gz
$ mv syncthing-macosx-amd64-v0.14.10 syncthing
$ cd syncthing
$ wget https://github.com/syncthing/syncthing-inotify/releases/download/v0.8.4/syncthing-inotify-darwin-amd64-v0.8.4.tar.gz
$ tar -xvzf syncthing-inotify-darwin-amd64-v0.8.4.tar.gz

On the LM, start syncthing and syncthing-inotify

$ nohup ~/syncthing/syncthing > /dev/null 2>&1 &
$ nohup ~/syncthing/syncthing-inotify > /dev/null 2>&1 &

You can now access the LM's syncthing web interface at http://127.0.0.1:8384.

On the RM, install syncthing

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-linux-amd64-v0.14.10.tar.gz
$ tar -xvzf syncthing-linux-amd64-v0.14.10.tar.gz
$ mv syncthing-linux-amd64-v0.14.10 syncthing
$ cd syncthing

On the RM, start syncthing

$ nohup ~/syncthing/syncthing -gui-address=http://0.0.0.0:8384 > /dev/null 2>&1 &

Find what's your RM's public IP (RMIP) and then open RM's syncthing web interface at http://`RMIP`:8384.


At this point, we need to wire up both machines and sync a folder.


Find the RM's ID

Open http://`RMIP`:8384 and press Show ID in the top menu, then copy that RM ID.

On the LM, add the RM device

Open http://127.0.0.1:8384, press Add Remote Device and in the popup add:

  • Device ID: RM ID from above
  • Device Name: yourProjectName

Then press Save.

On the RM, accept the LM device

On the RM web interface will appear a message to accept the connection from LM device. Press Add Device and in the popup press Save.

On the LM, add the shared folder in syncthing

Open http://127.0.0.1:8384, press Add Folder and in the popup add:

  • Folder Label: <yourProjectName>
  • Folder ID: <yourProjectName>
  • Folder Path: <pathToYourLocalProject>
  • Share with Devices > select <yourProjectName> device checkbox

Then press Save.

On the RM, accept the LM folder

On the RM web interface will appear a message to accept the shared folder from LM device. Press Add and in the popup:

  • Folder Path: <someRemoteFolderForMountingTheLMSharedFolderContent>

Then press Save.

We're all set, syncthing will now sync the LM folder to the RM remote folder, and vice-versa, each 60 secs, and syncthing-inotify will upload file changes instantly from LM to RM.



B. Linux64 LM & Linux64 RM

On the LM, install syncthing and syncthing-inotify

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-linux-amd64-v0.14.10.tar.gz
$ tar -xvzf syncthing-linux-amd64-v0.14.10.tar.gz
$ mv syncthing-linux-amd64-v0.14.10 syncthing
$ cd syncthing
$ wget https://github.com/syncthing/syncthing-inotify/releases/download/v0.8.4/syncthing-inotify-linux-amd64-v0.8.4.tar.gz
$ tar -xvzf syncthing-inotify-linux-amd64-v0.8.4.tar.gz

On the LM, start syncthing and syncthing-inotify

$ nohup ~/syncthing/syncthing > /dev/null 2>&1 &
$ nohup ~/syncthing/syncthing-inotify > /dev/null 2>&1 &

You can now access the LM's syncthing web interface at http://127.0.0.1:8384.

On the RM, install syncthing

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-linux-amd64-v0.14.10.tar.gz
$ tar -xvzf syncthing-linux-amd64-v0.14.10.tar.gz
$ mv syncthing-linux-amd64-v0.14.10 syncthing
$ cd syncthing

On the RM, start syncthing

$ nohup ~/syncthing/syncthing -gui-address=http://0.0.0.0:8384 > /dev/null 2>&1 &

Find what's your RM's public IP (RMIP) and then open RM's syncthing web interface at http://`RMIP`:8384.


At this point, we need to wire up both machines and sync a folder.


Find the RM's ID

Open http://`RMIP`:8384 and press Show ID in the top menu, then copy that RM ID.

On the LM, add the RM device

Open http://127.0.0.1:8384, press Add Remote Device and in the popup add:

  • Device ID: RM ID from above
  • Device Name: yourProjectName

Then press Save.

On the RM, accept the LM device

On the RM web interface will appear a message to accept the connection from LM device. Press Add Device and in the popup press Save.

On the LM, add the shared folder in syncthing

Open http://127.0.0.1:8384, press Add Folder and in the popup add:

  • Folder Label: <yourProjectName>
  • Folder ID: <yourProjectName>
  • Folder Path: <pathToYourLocalProject>
  • Share with Devices > select <yourProjectName> device checkbox

Then press Save.

On the RM, accept the LM folder

On the RM web interface will appear a message to accept the shared folder from LM device. Press Add and in the popup:

  • Folder Path: <someRemoteFolderForMountingTheLMSharedFolderContent>

Then press Save.

We're all set, syncthing will now sync the LM folder to the RM remote folder, and vice-versa, each 60 secs, and syncthing-inotify will upload file changes instantly from LM to RM.



C. Win64 LM & Linux64 RM

You need to install cygwin to be able to have tools like wget, tar, unzip, which are used below. Start the cygwin terminal and follow next steps.

On the LM, install syncthing and syncthing-inotify

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-windows-amd64-v0.14.10.zip
$ unzip syncthing-windows-amd64-v0.14.10.zip
$ mv syncthing-windows-amd64-v0.14.10 syncthing
$ cd syncthing
$ wget https://github.com/syncthing/syncthing-inotify/releases/download/v0.8.4/syncthing-inotify-windows-amd64-v0.8.4.tar.gz
$ tar -xvzf syncthing-inotify-windows-amd64-v0.8.4.tar.gz

On the LM, start syncthing and syncthing-inotify

Open 2 cygwin terminals to start the below binaries:

$ ~/syncthing/syncthing.exe
$ ~/syncthing/syncthing-inotify.exe

or create one .vbs script for each binary, syncthing.vbs

CreateObject("Wscript.Shell").Run "~/syncthing/syncthing.exe, 0, True

and syncthing-inotify.vbs

CreateObject("Wscript.Shell").Run "~/syncthing/syncthing-inotify.exe, 0, True

and execute them.

You can now access the LM's syncthing web interface at http://127.0.0.1:8384.

On the RM, install syncthing

$ cd ~
$ wget https://github.com/syncthing/syncthing/releases/download/v0.14.10/syncthing-linux-amd64-v0.14.10.tar.gz
$ tar -xvzf syncthing-linux-amd64-v0.14.10.tar.gz
$ mv syncthing-linux-amd64-v0.14.10 syncthing
$ cd syncthing

On the RM, start syncthing

$ nohup ~/syncthing/syncthing -gui-address=http://0.0.0.0:8384 > /dev/null 2>&1 &

Find what's your RM's public IP (RMIP) and then open RM's syncthing web interface at http://`RMIP`:8384.


At this point, we need to wire up both machines and sync a folder.


Find the RM's ID

Open http://`RMIP`:8384 and press Show ID in the top menu, then copy that RM ID.

On the LM, add the RM device

Open http://127.0.0.1:8384, press Add Remote Device and in the popup add:

  • Device ID: RM ID from above
  • Device Name: yourProjectName

Then press Save.

On the RM, accept the LM device

On the RM web interface will appear a message to accept the connection from LM device. Press Add Device and in the popup press Save.

On the LM, add the shared folder in syncthing

Open http://127.0.0.1:8384, press Add Folder and in the popup add:

  • Folder Label: <yourProjectName>
  • Folder ID: <yourProjectName>
  • Folder Path: <pathToYourLocalProject>
  • Share with Devices > select <yourProjectName> device checkbox

Then press Save.

On the RM, accept the LM folder

On the RM web interface will appear a message to accept the shared folder from LM device. Press Add and in the popup:

  • Folder Path: <someRemoteFolderForMountingTheLMSharedFolderContent>

Then press Save.

We're all set, syncthing will now sync the LM folder to the RM remote folder, and vice-versa, each 60 secs, and syncthing-inotify will upload file changes instantly from LM to RM.



That's all folks, let us know your feedback.

Want more awesome stuff?

Check us out on our Medium Remote Symfony Team publication.