<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title> - self-hosting</title>
    <link rel="self" type="application/atom+xml" href="https://www.callumirving.com/tags/self-hosting/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://www.callumirving.com"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2023-05-30T00:00:00+00:00</updated>
    <id>https://www.callumirving.com/tags/self-hosting/atom.xml</id>
    <entry xml:lang="en">
        <title>Running Syncthing on a VPS</title>
        <published>2023-05-30T00:00:00+00:00</published>
        <updated>2023-05-30T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://www.callumirving.com/blog/syncthing-vps/"/>
        <id>https://www.callumirving.com/blog/syncthing-vps/</id>
        
        <content type="html" xml:base="https://www.callumirving.com/blog/syncthing-vps/">&lt;p&gt;I&#x27;ve been going down the self-hosting rabbit hole recently and decided to try out &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;syncthing.net&#x2F;&quot;&gt;Syncthing&lt;&#x2F;a&gt; as a way of syncing notes across my devices. I decided to run a node on a VPS so that I would have one node running 24&#x2F;7 that my devices can sync to. This guide will help you set up Syncthing on a VPS and secure it using &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;launchpad.net&#x2F;ufw&quot;&gt;ufw&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.fail2ban.org&#x2F;wiki&#x2F;index.php&#x2F;Main_Page&quot;&gt;fail2ban&lt;&#x2F;a&gt;. This guide will only use the command line (no web GUI).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;installing&quot;&gt;Installing&lt;&#x2F;h2&gt;
&lt;p&gt;The installation process varies depending on which OS you are running on the server but most common Linux distros should have a version of Syncthing packaged in the default repositories. We are also going to install &lt;code&gt;fail2ban&lt;&#x2F;code&gt; for security.&lt;&#x2F;p&gt;
&lt;p&gt;For Ubuntu or Debian server:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; sudo apt install syncthing fail2ban&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For Arch:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; sudo pacman&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; -S&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing ufw fail2ban&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For Fedora:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; sudo dnf install syncthing ufw fail2ban&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;security&quot;&gt;Security&lt;&#x2F;h2&gt;
&lt;h3 id=&quot;disclaimer&quot;&gt;Disclaimer&lt;&#x2F;h3&gt;
&lt;p&gt;I am not a security expert. Do your own research before following these instructions.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;enable-fail2ban&quot;&gt;Enable &lt;code&gt;fail2ban&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;All you have to do to enable fail2ban is run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; systemctl enable fail2ban&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; systemctl start fail2ban&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h3 id=&quot;opening-ports-on-vps&quot;&gt;Opening ports on VPS&lt;&#x2F;h3&gt;
&lt;p&gt;The ports we are going to need open for Syncthing are 22000 and 21027&#x2F;udp. Your VPS provider should have instructions on opening ports.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;setting-up-ufw&quot;&gt;Setting up &lt;code&gt;ufw&lt;&#x2F;code&gt;&lt;&#x2F;h3&gt;
&lt;p&gt;&lt;code&gt;ufw&lt;&#x2F;code&gt; (uncomplicated firewall) is an easy-to-use firewall tool that we will use to drop all incoming traffic on ports other than the Syncthing ports. We can allow traffic on Syncthing ports by running&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; sudo ufw allow syncthing&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you are using SSH to access your VPS it is also important that your open the SSH port so you don&#x27;t get locked out. To do this, run &lt;code&gt;sudo ufw allow ssh&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;configuration&quot;&gt;Configuration&lt;&#x2F;h2&gt;
&lt;p&gt;To generate a Syncthing config on the server, run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing generate&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;This should output a device ID, make sure to save this for later. I will refer to this as &lt;code&gt;SERVER_ID&lt;&#x2F;code&gt; from now on.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;connecting-a-device&quot;&gt;Connecting a device&lt;&#x2F;h3&gt;
&lt;p&gt;These next instructions will show you how to connect a device, such as a laptop or desktop computer, to the server. First, make sure Syncthing is running on both the device and the server. Start Syncthing on the server by running the following two commands:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; systemctl enable syncthing@USER.service&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; systemctl start syncthing@USER.service&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;where &lt;code&gt;USER&lt;&#x2F;code&gt; is replaced by your username.&lt;&#x2F;p&gt;
&lt;p&gt;First, we will need the device ID of the device. Run &lt;code&gt;syncthing -device-id&lt;&#x2F;code&gt; to get it. I will refer to this as &lt;code&gt;LOCAL_ID&lt;&#x2F;code&gt; from now on. On your local device, run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing cli config devices add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; --device-id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; LOCAL_ID&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and on your local device run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing cli config devices add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; --device-id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; SERVER_ID&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To configure the server to auto-accept folders from the local device, run the following command on the server:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing cli config devices LOCAL_ID auto-accept-folders set&lt;&#x2F;span&gt;&lt;span style=&quot;color: #D2A6FF;&quot;&gt; true&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now you can add a folder from your local device. On the local device, run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing cli config folders list&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;and copy the folder ID of the folder you want to add. Then run&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #BFBDB6; background-color: #0D1017;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #59C2FF;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; syncthing cli config folders FOLDER_ID devices add&lt;&#x2F;span&gt;&lt;span style=&quot;color: #95E6CB;&quot;&gt; --device-id&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AAD94C;&quot;&gt; SERVER_ID&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;to add the folder.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;credits&quot;&gt;Credits&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;Thanks to &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;Jonny-exe&quot;&gt;jonny-exe&lt;&#x2F;a&gt; for creating &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;Jonny-exe&#x2F;9bad76c3adc6e916434005755ea70389&quot;&gt;this gist&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;superuser.com&#x2F;questions&#x2F;1397683&#x2F;how-can-i-configure-syncthing-from-command-line-to-share-a-folder-with-another-c&#x2F;1731999#1731999?s=0744928a5f9d4717b7445d039785ba53&quot;&gt;This superuser post&lt;&#x2F;a&gt; was also great.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
