Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save smjure/cbdc6eaab6ce354e7d7f39cccaa8991c to your computer and use it in GitHub Desktop.
Save smjure/cbdc6eaab6ce354e7d7f39cccaa8991c to your computer and use it in GitHub Desktop.
syncthing setup exclusively with CLI

GCE Instance example [1.23 has Telemetry, switch it off go telemetry off]

image

WHEN YOU SETUP NEW GCE, DO IT IN THE MORNING THEN TEST RUNNING UNTIL YOUR 13:46, BECAUSE THE FIRST DAY ALWAYS FLIPS OUT FOR SOME STRANGE REASON. ESPECIALLY TEST:

  • Telegram commands (statsBot): news, day, stats, etc.
  • Terminal commands (statsBot): news, day, stats, etc.
  • screen command (detech a couple of times), just this time it was a reason for a flip out
  • Close terminal and let screen running in backend

GCE gcloud command: setup ssh key and connect to the desired VM instance

  1. create ssh key:https://cloud.google.com/compute/docs/connect/create-ssh-keys
  2. add pub key to VM: https://cloud.google.com/compute/docs/connect/add-ssh-keys#os-login
  3. ssh connect to VM: https://cloud.google.com/compute/docs/connect/standard-ssh

Syncthing setup on Linux

Syncthing setup: https://www.linuxbabe.com/ubuntu/install-syncthing-ubuntu-desktop-server

START / STOP Syncthing Service

This is useful for automated bash scripts.

sudo systemctl start syncthing@$USER.service

sudo systemctl stop syncthing@$USER.service

sudo systemctl enable syncthing@$USER # enable autostart at boot

syncthing cli operations restart/shutdown # syncthing CLI interface

After long searching I did not find a good description of how to set up Syncthing that works exclusively via CLI without using a Web browser on the devices.

This is useful for example on a headless Raspberry Pi without proxying web-traffic through SSH or with port-forwarding limitations. In this example we will want to share the default folder from Machine A with Machine B

Machine A Machine B

Install Syncthing

On debian:
sudo apt install syncthing

On fedora:
sudo dnf install syncthing

Generate device ID and config files and default folder

syncthing generate

Start Syncthing

syncthing --no-browser

Get the device id

syncthing --device-id

Install Syncthing

On debian:
sudo apt install syncthing

On fedora:
sudo dnf install syncthing

Generate device ID and config files and default folder

syncthing generate

Start Syncthing

syncthing --no-browser

Get the device id

syncthing --device-id

Add Machine B

syncthing cli config devices add --device-id $DEVICE_ID_B

Add Machine A

syncthing cli config devices add --device-id $DEVICE_ID_A

Share default folder with Machine B

syncthing cli config folders $FOLDER_ID devices add --device-id $DEVICE_ID_B

Insert the id from the folder you want to share into $FOLDER_ID

Accept default folder from Machine A
syncthing cli config devices $DEVICE_ID_A auto-accept-folders set true

If you don't want Machine B automatically accepting all of Machine A's folder requests, just run this command again with false

Additional useful info can be found at: https://superuser.com/questions/1397683/how-can-i-configure-syncthing-from-command-line-to-share-a-folder-with-another-c/1731999#1731999?s=0744928a5f9d4717b7445d039785ba53.

Don't waste your time with this repo, as it hasn't been updated since 2014, it is not working: https://github.com/classicsc/syncthingmanager

This repo https://github.com/tenox7/stc is useful but it doesn't not offer adding devices/folders.

Tailscale setup [for LLMs usage on SM]

Must setup tailscale: https://tailscale.com/kb/1031/install-linux
Login on GCE by sudo tailscale login and the outputed URL copy/paste in any browser on any comp (not needed on the GCE itself) :) and just login with your smjure account, yes it's that simple

Enabling Swap on Ubuntu

If you decide to enable swap, you can create a swap file with the following steps:

  1. Create a Swap File:

sudo fallocate -l 2G /swapfile

Replace 2G with the desired size of your swap file.

  1. Secure the Swap File:

sudo chmod 600 /swapfile

  1. Set Up the Swap File:

sudo mkswap /swapfile

  1. Enable the Swap File:

sudo swapon /swapfile

  1. Make the Swap File Permanent:

Add the following line to your /etc/fstab file: /swapfile none swap sw 0 0

By following these steps, you can enable swap on your Ubuntu server, providing an additional layer of memory management and system stability.

Crontab job

If crontab -e is not awailable, you have to install the cron command:

sudo apt-get update
sudo apt-get install cron

After that paste your needed jobs [CAREFUL WHICH TIMEZONE YOU HAVE SET!!!]:

11 20 * * * /home/oem/Sync/tarAllFiles.sh # tar manually

08 13 * * * sudo /usr/bin/pkill realTime >> /home/oem/Sync/pkill.log 2>&1

09 21 * * * sudo shutdown now # to be sure shutdown the GCE every day at 

# @reboot sleep 5 && /usr/bin/syncthing -allow-newer-config

[Have tried to change it but it does not really work] Timezone change from UTC to NYC [DO THIS BEFOR CREATING ANY GCE INSTANCE]

Do not forget to change/adjust crontab jobs accordingly \

Compute Engine --> Settings --> Set default region:us-east4(Northern Virginia and zone:us-east4-a/b/c\

In an existing GCE VM instance, you can change the region and timezone (but seems not working)

Go to desired instance --> EDIT --> Metadata --> ADD ITEM and add key-value pair:timezone & America/New_York

Fastfetch instances I used

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment