Syncthing is amazing alternative to things like Dropbox or Google Drive plus you control your data. Now it works little differently than usual cloud storage solutions. Instead of one central server Syncthing uses peer to peer sharing. Also Syncthing is quite flexible for sharing files between your different devices or between people. I will not go into details of Syncthing features and options because probably if you are already here you want to know how to install it so here goes …
Syncthing has its own repository and signing key. Download and install the signing key, run:
wget -O - https://syncthing.net/release-key.txt | sudo apt-key add -
This key is required in order for apt-get to install any packages that it was used to sign.
Next, add the Syncthing repository to APT’s list of known sources by creating a new source list. Run:
sudo nano /etc/apt/sources.list.d/syncthing.list
And add following to file:
deb http://apt.syncthing.net/ syncthing release
Save your changes.
Now we will install syncthing.
sudo apt-get update
sudo apt-get install syncthing
Now you can configure Syncthing from browser if you use a desktop enviorement but because I use Pi as headless server we will do configuration via terminal.
Start and close syncthing.
syncthing
CTRL+C
Open Syncthing’s configuration file using nano:
sudo nano ~/.config/syncthing/config.xml
Find the GUI section similar to this:
<gui enabled="true" tls="false" debugging="false">
<address>127.0.0.1:8384</address>
<apikey></apikey>
<theme>default</theme>
</gui>
And replace the 127.0.0.1:8384 with 0.0.0.0:8384.
Now any machine on the local network can access the program.
Save and Close
Start the Syncthing
Navigate your browser to the Raspberry Pi-s IP with port 8384.
Proceed with “Settings” button.
Fill in values for the “GUI Authentication User” and password.
Now Syncthing automatically created sync folder to Raspberry Pi-s home folder. Now we need second computer with Syncthing. I use my main PC for that so just install Syncthing on second computer (for my Linux Mint I just downloaded the 64bit linux package from their website, unpacked and ran).
Now we have to introduce two Syncthings to each other.
Click “Action” drop down menu and select “Show ID”
Now on Pi select “Add Remote Device” from the lower part of the page.
Copy the code above the QR code from second device to Raspberry Pi-s Device ID field.
Check the “Default Folder” checkbox at the bottom.
Click “Save”
Return to second devices Web UI. There should be prompt asking to approve the device. Click “Add Device”
You will be prompted the familiar “Add Device” form.
Check the “Default Folder” box and click “Save”
Now after 20 seconds both UI-s show the Remote device status connected and after that Up to Date. (You may need to confirm the sharing of folder on Raspberry Pi after 19. step)
Testing:
Add a file to your “Sync” folder and if internet gods are merciful the file will appear on second computer.
Now Syncthing is very well documented so I recommend to read their documentation @ https://docs.syncthing.net/
Installazione
Innanzitutto scarichiamo la chiave gpg per poter aggiungere in seguito il repository debian.
wget -O - https://syncthing.net/release-key.txt | sudo apt-key add -
Ora aggiungiamo il repository
echo "deb http://apt.syncthing.net/ syncthing release" | sudo tee -a /etc/apt/sources.list.d/syncthing-release.list
Aggiorniamo il repository
sudo apt-get update
sudo apt-get install syncthing -y
Ora facciamo partire syncthing una prima volta. Questa operazione crea i files di configurazione nella home dell’utente con cui abbiamo lanciato il programma. Digitate quindi
syncthing
Dovreste vedere un output tipo questo
[monitor] 17:45:33 INFO: Starting syncthing
[start] 17:45:33 INFO: Generating RSA key and certificate for syncthing...
[HR2B5] 17:47:33 INFO: syncthing v0.11.12 (go1.4.2 linux-arm default) unknown-user@syncthing-builder 2015-07-05 09:24:21 UTC
[HR2B5] 17:47:33 INFO: My ID: HR2B56D-52WUAGB-36PBQRH-VBU3AAN-YS6SXIM-LJXVBZP-BR3CEMP-STI4EQW
[HR2B5] 17:47:33 INFO: No config file; starting with empty defaults
[HR2B5] 17:47:33 INFO: Edit /home/pi/.config/syncthing/config.xml to taste or use the GUI
[HR2B5] 17:47:33 INFO: Database block cache capacity 8192 KiB
[HR2B5] 17:47:33 OK: Ready to synchronize default (read-write)
[HR2B5] 17:47:33 INFO: Starting web GUI on http://127.0.0.1:8384/
[HR2B5] 17:47:33 INFO: Loading HTTPS certificate: open /home/pi/.config/syncthing/https-cert.pem: no such file or directory
[HR2B5] 17:47:33 INFO: Creating new HTTPS certificate
[HR2B5] 17:47:33 INFO: Generating RSA key and certificate for raspberrypi...
[HR2B5] 17:47:33 INFO: Completed initial scan (rw) of folder default
Ora fermiamo il programma premendo Ctrl-C
La configurazione standard di syncthing, prevede che l’accesso alla sua pagina web di configurazione, possa avvenire solo dalla macchina locale. Stiamo installando syncthing su una raspberry quindi è ovvio che dobbiamo accedervi da remoto. Apriamo quindi il file di configurazione per modificare tale impostazione.
vi /home/pi/.config/syncthing/config.xml
Nel file dobbiamo cambiare la riga con scritto 127.0.0.1 (solo accessibile dalla macchina locale) in 0.0.0.0 (accessibile da tutte le macchine)
Modificare tls in true se volete attivare l’ssl per l’interfaccia di configurazione.
<gui enabled="true" tls="false">
<address>0.0.0.0:8384</address>
<apikey>VbsKT2fCELYldTI74Tk4BKCbJP8Frlij</apikey>
</gui>
Autostart di Syncthing su Raspberry Pi
Creare il file di init.d
sudo vi /etc/init.d/syncthing
Incollateci dentro questo:
*************************************** INIZIO
#!/bin/sh
### BEGIN INIT INFO
# Provides: Syncthing
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Syncthing
# Description: Syncthing is for backups
### END INIT INFO
# Documentation available at
# http://refspecs.linuxfoundation.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
# Debian provides some extra functions though
. /lib/lsb/init-functions
DAEMON_NAME="syncthing"
DAEMON_USER=pi
DAEMON_PATH="/usr/bin/syncthing"
DAEMON_OPTS=""
DAEMON_PWD="${PWD}"
DAEMON_DESC=$(get_lsb_header_val $0 "Short-Description")
DAEMON_PID="/var/run/${DAEMON_NAME}.pid"
DAEMON_NICE=0
DAEMON_LOG='/var/log/syncthing'
[ -r "/etc/default/${DAEMON_NAME}" ] && . "/etc/default/${DAEMON_NAME}"
do_start() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -eq 0 ]; then
log_warning_msg "${DAEMON_NAME} is already started"
result=0
else
log_daemon_msg "Starting ${DAEMON_DESC}" "${DAEMON_NAME}"
touch "${DAEMON_LOG}"
chown $DAEMON_USER "${DAEMON_LOG}"
chmod u+rw "${DAEMON_LOG}"
if [ -z "${DAEMON_USER}" ]; then
start-stop-daemon --start --quiet --oknodo --background \
--nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
else
start-stop-daemon --start --quiet --oknodo --background \
--nicelevel $DAEMON_NICE \
--chdir "${DAEMON_PWD}" \
--pidfile "${DAEMON_PID}" --make-pidfile \
--chuid "${DAEMON_USER}" \
--exec "${DAEMON_PATH}" -- $DAEMON_OPTS
result=$?
fi
log_end_msg $result
fi
return $result
}
do_stop() {
local result
pidofproc -p "${DAEMON_PID}" "${DAEMON_PATH}" > /dev/null
if [ $? -ne 0 ]; then
log_warning_msg "${DAEMON_NAME} is not started"
result=0
else
log_daemon_msg "Stopping ${DAEMON_DESC}" "${DAEMON_NAME}"
killproc -p "${DAEMON_PID}" "${DAEMON_PATH}"
result=$?
log_end_msg $result
rm "${DAEMON_PID}"
fi
return $result
}
do_restart() {
local result
do_stop
result=$?
if [ $result = 0 ]; then
do_start
result=$?
fi
return $result
}
do_status() {
local result
status_of_proc -p "${DAEMON_PID}" "${DAEMON_PATH}" "${DAEMON_NAME}"
result=$?
return $result
}
do_usage() {
echo $"Usage: $0 {start | stop | restart | status}"
exit 1
}
case "$1" in
start) do_start; exit $? ;;
stop) do_stop; exit $? ;;
restart) do_restart; exit $? ;;
status) do_status; exit $? ;;
*) do_usage; exit 1 ;;
esac
*************************************** FINE
Rendere il file eseguibile
sudo chmod +x /etc/init.d/syncthing
Impostare lo startup del servizio alla partenza della raspberrypi
sudo update-rc.d syncthing defaults