Skip to main content

CLI Flags and Environment Variables

Syncthing's CLI has changed significantly since v1.20. The modern syncthing serve subcommand replaces the old syncthing root invocation for running the daemon. This reference covers all stable flags and environment variables.

Learning Focus

In systemd units, use environment variables for configuration that varies by environment (API keys, log level). Use CLI flags only for immutable startup behavior (home dir, no-browser).

Subcommands

SubcommandPurpose
syncthing serveStart the Syncthing daemon (primary command)
syncthing generateGenerate a config and cert without starting
syncthing decryptDecrypt a receive-encrypted folder (for recovery)
syncthing --versionPrint version and exit
syncthing --device-idPrint the Device ID and exit

syncthing serve Flags

syncthing serve [flags]
FlagDefaultDescription
--home=PATH~/.local/share/syncthingPath to config/data directory
--config=PATH$HOME/config.xmlExplicitly set config file path
--data=PATHSame as --homeSeparate path for database files
--no-browserfalseDo not open the web browser on startup
--no-restartfalseDo not auto-restart after crash (systemd handles this)
--logfile=PATH(stdout)Write logs to a file instead of stdout
--logflags=N3Bitmask for log line prefix: 0=none, 1=date, 2=time, 3=date+time
--log-max-size=N10485760 (10 MB)Max log file size before rotation
--log-max-old-files=N3Number of rotated log files to keep
--allow-newer-configfalseAllow config written by a newer version
--gui-address=ADDR127.0.0.1:8384Override GUI/API bind address
--gui-apikey=KEY(from config)Override API key for this session

Common Usage Patterns

serve-examples.sh
# Standard production startup (no browser, systemd handles restart)
syncthing serve --no-browser --no-restart --logflags=0

# Custom home directory (e.g., for a system user)
syncthing serve --home=/home/syncthing/.local/share/syncthing --no-browser

# Bind GUI to a different port
syncthing serve --no-browser --gui-address=127.0.0.1:9999

# Override API key (useful for one-off scripting)
syncthing serve --no-browser --gui-apikey=temporarykey123

# Generate verbose debug output
STTRACE=all syncthing serve --no-browser 2>&1 | tee /tmp/syncthing-debug.log

syncthing generate Flags

Generate a config and TLS certificate without running:

generate-examples.sh
# Generate in the default home directory
syncthing generate

# Generate in a custom directory
syncthing generate --home=/opt/syncthing-data

# Generate without user interaction (for scripted deployments)
syncthing generate --no-default-folder

syncthing decrypt Flags

Recover files from a receiveencrypted folder:

decrypt-examples.sh
# Decrypt files from an encrypted repository (requires encryption password)
syncthing decrypt \
--from=/mnt/encrypted-backup \
--to=/tmp/recovered \
--password=yourFolderEncryptionPassword \
--verify-only # Dry run — verify without writing

Environment Variables

VariableEffect
STNOUPGRADESet to 1 to disable the built-in auto-upgrade (recommended in package-managed installs)
STLEVELSet log verbosity: verbose, debug
STTRACEComma-separated trace categories (e.g., beacon,db,protocol). all for everything.
STPROFILERAddress to start Go pprof HTTP profiler (e.g., 127.0.0.1:6060)
GOMAXPROCSLimit Go runtime parallelism (e.g., 2 to cap at 2 threads)
STGUIADDRESSOverride GUI bind address (alternative to --gui-address)
STGUIAPIKEYOverride GUI API key (alternative to --gui-apikey)
STNODEFAULTFOLDERSet to 1 to skip creating the default ~/Sync folder on first run
HOMEStandard Linux home dir — affects default config path if --home not set

Systemd Service Environment Example

/etc/systemd/system/syncthing@.service (relevant section)
[Service]
User=%I
Environment=STNOUPGRADE=1
Environment=GOMAXPROCS=2
Environment=STLEVEL=info
ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=0

Trace Categories for Debugging

When setting STTRACE:

CategoryWhat It Logs
beaconLocal discovery beacon traffic
dbDatabase read/write operations
protocolBEP protocol messages between peers
modelFile model sync decisions
netNetwork connection events
relayRelay server interactions
upnpUPnP port mapping attempts
versionerFile versioning operations
debug-protocol.sh
# Trace only protocol and relay for connection debugging
STTRACE=protocol,relay syncthing serve --no-browser 2>&1 | grep -E "\[TRACE\]"

Flag Precedence

flowchart LR
CLI[CLI Flags] --> ENV[Environment Variables]
ENV --> CONF[config.xml values]
CONF --> DEFAULTS[Built-in defaults]
CLI -- highest priority --> CONF

CLI flags take highest precedence, followed by environment variables, then config.xml, then compiled defaults.

What's Next