How to Install Syncthing on AlmaLinux 9
Syncthing is an open-source, peer-to-peer file synchronization tool designed to securely sync files across multiple devices. Unlike cloud-based services, Syncthing operates directly between devices without storing data on external servers, giving users full control over their files and privacy. It works by using encrypted communication between devices, ensuring that data is transferred securely. Syncthing can be used to synchronize files between computers, mobile devices, and even servers, making it a versatile solution for users who need reliable, private, and real-time file syncing. It's easy to set up, cross-platform, and runs in the background, automatically syncing files whenever changes are detected.
In this guide, you will learn how to install Syncthing software on AlmaLinux 9 servers. You will also learn how to connect between two syncthing instances and set up a shared folder in syncthing.
Prerequisites
Before you begin, ensure you have the following:
- Two AlmaLinux 9 machines.
- A non-root user with administrator privileges.
- A SELinux with permissive mode.
Downloading Syncthing Binary File
For RHEL-based distribution, you need to install syncthing manually via binary file. Be sure to check the official GitHub page for syncthing to get the latest version of syncthing.
First, run the command below to install curl, wget, and nano editor packages to your systems.
sudo dnf install curl wget nano -y
Now download the syncthing binary file from the GitHub repository using the following command.
curl -s https://api.github.com/repos/syncthing/syncthing/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
Once downloaded, extract the syncthing tar.gz file using the command below. Then move the syncthing binary file to the /usr/bin/ directory.
tar xvf syncthing-linux-amd64*.tar.gz
sudo mv syncthing-linux-amd64-*/syncthing /usr/bin/
Lastly, verify the location of the syncthing binary file and version using the command below.
which syncthing
syncthing --version
Based on the following output, you can see syncthing xxx is installed at /usr/bin/syncthing.
Running Syncthing as Systemd Service
Syncthing can be run manually, but it is easier to run syncthing as a systemd service. You can control the syncthing service using the systemctl utility.
Run the following nano editor command to create a new systemd service file /etc/systemd/system/[email protected].
sudo nano /etc/systemd/system/[email protected]
Insert the following configuration into the file.
[Unit]
Description=Syncthing - Open Source Continuous File Synchronization for %I
Documentation=man:syncthing(1)
After=network.target
[Service]
User=%i
ExecStart=/usr/bin/syncthing -no-browser -gui-address=0.0.0.0:8384 -no-restart -logflags=0
Restart=on-failure
SuccessExitStatus=3 4
RestartForceExitStatus=3 4
# Hardening
ProtectSystem=full
PrivateTmp=true
SystemCallArchitectures=native
MemoryDenyWriteExecute=true
NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
Save the file and exit the editor when you're done.
Lastly, and most importantly, reload the systemd manager using the below command to apply the changes on your system.
sudo systemctl daemon-reload
Setting Up Firewalld
Now that you've configured syncthing as a systemd service, you will need to open ports for syncthing via firewalld. By default, firewalld includes the syncthing application, you can easily enable it.
Execute the command below to add and enable syncthing and syncthing-gui services on firewalld.
sudo firewall-cmd --zone=public --add-service=syncthing --permanent
sudo firewall-cmd --zone=public --add-service=syncthing-gui --permanent
Now reload the firewalld to take effect, then verify the list of enabled services on firewalld.
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
As you can see in the following output, the syncthing profile is enabled.
Initializing Syncthing Node
Before you start connecting syncing instances, you must initialize syncthing per-user on your system. In this example, we'll use two Almalinux servers with different users below:
- node1 with user tom
- node2 server with user jerry
Now, run the following command to start the syncthing service and initialize the syncthing installation. Be sure to change the user tom with your username.
sudo systemctl start [email protected]
Once the syncthing service is started, the new configuration directory ~/.local/state/synching and Sync directory will be created. Verify it using the command below.
ls -ah ~/Sync
ls -ah ~/.local/state/syncthing/
After that, open the syncthing configuration ~/.local/state/syncthing/config.xml using the nano editor command below.
sudo nano ~/.local/state/syncthing/config.xml
Within the 'gui' section, change the option 'tls=false' to 'tls=true' to enable secure access for syncthing.
<gui enabled="true" tls="true" debugging="false" sendBasicAuthPrompt="false">
<address>192.168.10.41:8384</address>
<apikey>GENERATED-API-KEY</apikey>
<theme>default</theme>
</gui>
Save the file and exit the editor when you're done.
Then, run the command below to restart syncthing and apply your changes.
sudo systemctl restart [email protected]
Next, enable and verify the syncthing service using the command below. Ensure you get an output enabled and active(running), which confirms that the syncthing service status is running.
sudo systemctl enable [email protected]
sudo systemctl status [email protected]
Setting up User and Password for Syncthing
Now that you've started and initialized syncthing, the next step you will configure user authentication for your syncthing instance.
Before you start, run the ss command below to ensure port 8384 is in the LISTEN state.
ss -tulpn | grep 8384
In the following output, you can see port 8384 is used by syncthing.
Open your web browser and visit the server IP address followed by port 8384 (i.e: https://192.168.5.15:8384/). If your installation is successful, you should get the welcome page below.
Click on the Settings menu to set up user authentication.
Click on the GUI tab, then input your admin user and password. Be sure to check the option Use HTTPS for GUI. Press Save to confirm your changes.
Now you will be redirected to the syncthing login page. From there, input your username and password, then click Login.
If your configuration is successful, you will be presented with a syncthing dashboard like the following:
Below you can see the syncthing dashboard from node2.
Connecting Syncthing Instance
At this point, you've finished the installation of syncthing on both Almalinux servers. It's time to connect both syncthing instances, which can be done via the web administration dashboard.
On the node1 dashboard, click Action and select Show ID to get details of the node ID.
You can see the ID and qrcode of the node1 instance. Copy the node1 ID, you will need it for connecting to the node2 instance.
Now move to the node2 dashboard, on the Remote Devices section, click Add Remote Device.
Paste the ID of node1, and input the name as node1.
Next, move to the Sharing tab. In the Unshared Folders section, check the option Default Folder to share the target folder to the node1.
Also, be sure to check the Auto Accept option to automatically create or share folders that node1 advertises in the default path.
Click Save to confirm.
Move back to the node1 dashboard and you should see request messages from the node2. Click Add Device to confirm.
When prompted, click Save to confirm. Also, be sure to check the device ID of node2.
Next, you will get another notification that the node2 instance will share the folder Default Folder, click Share to confirm.
Once the process is finished, you can see on the node1 the following information:
- The Default Folder with path /home/tom/Sync is Shared With node2.
- On the Remote Devices section, you can see the node2 with status Up To Date.
Now check the node2 dashboard, you should see similar information that the Default Folder is Shared With node1. Also, you can see on the Remote Devices section the node1 with status Up to Date.
Test File Sync
At this point, you've completed the configuration of the shared folder between two syncthing instances. Now, let's try to create new files on the Shared directory to verify synchronization between two syncthing instances.
On the node1 server, move to the ~/Sync directory and execute the following command to create new files.
cd ~/Sync/
touch file{1..50}.txt
ls -ah
Now move to the node2 server and go to the ~/Sync directory. Then, verify the list files on the ~/Sync directory.
cd ~/Sync
ls -ah
If your synchronization is successful, you should see files that you've created from the node1 server.
With this, your syncthing installation is successful.
Conclusion
Congratulations! You have successfully installed syncthing on AlmaLinux 9 servers. You've also learned how to connect between syncthing instances, set up a shared folder, and verify the synchronization of syncthing instances.
From her, you can now add more devices and connect to your current instance to enable file sharing and synchronization between multiple devices.