<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://lamplightservers.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://lamplightservers.github.io/" rel="alternate" type="text/html" /><updated>2026-11-18T10:10:16+00:00</updated><id>https://lamplightservers.github.io/feed.xml</id><title type="html">Lamplight Servers</title><subtitle>Tested, copy-paste self-hosting tutorials for your own VPS.</subtitle><entry><title type="html">Run Your Own Vaultwarden Password Manager on a VPS with Docker</title><link href="https://lamplightservers.github.io/run-your-own-vaultwarden-password-manager-on-a-vps-with-dock/" rel="alternate" type="text/html" title="Run Your Own Vaultwarden Password Manager on a VPS with Docker" /><published>2026-11-18T10:09:51+00:00</published><updated>2026-11-18T10:09:51+00:00</updated><id>https://lamplightservers.github.io/run-your-own-vaultwarden-password-manager-on-a-vps-with-dock</id><content type="html" xml:base="https://lamplightservers.github.io/run-your-own-vaultwarden-password-manager-on-a-vps-with-dock/"><![CDATA[<p>Password managers hold the keys to everything you own online, yet the hosted ones put that vault on someone else’s servers and often lock useful features behind a subscription. If you’d rather keep control of your own data, self-hosting is a realistic option, even on a small VPS.</p>

<p>In this guide we build a private Vaultwarden server, a lightweight, Bitwarden-compatible backend, running in Docker. It is never exposed to the public internet and is reachable only through an SSH tunnel. We also add automatic daily backups and disable public sign-ups, so the only account on the server is yours. You get the polished Bitwarden apps and extensions, with a vault that lives on a machine you control.</p>

<iframe width="100%" style="aspect-ratio:16/9" src="https://www.youtube-nocookie.com/embed/eMYS1ldxhh4" title="Video tutorial" frameborder="0" allowfullscreen=""></iframe>

<h2 id="what-you-need">What you need</h2>

<ul>
  <li>A VPS with Ubuntu 24.04 (2 vCPU / 4 GB RAM is plenty). I use <a href="https://www.vdsina.com/?partner=xuevxsn1ece5">VDSina</a> <em>(affiliate link — it supports the channel at no extra cost to you)</em>.</li>
  <li>An SSH connection to it (any terminal works).</li>
</ul>

<blockquote>
  <p>Short on time? Every command below is also in <a href="https://github.com/lamplightservers/lamplightservers.github.io/blob/main/scripts/run-your-own-vaultwarden-password-manager-on-a-vps-with-dock/install.sh">one ready-to-run script</a>.</p>
</blockquote>

<h2 id="step-1-update-the-system">Step 1: Update the system</h2>

<p>Refresh the package list and install pending updates so the server has the latest security patches. A machine that stores your passwords should be fully patched before anything else goes on it, and the update may take a minute or two.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>apt-get update <span class="o">&amp;&amp;</span> <span class="nv">DEBIAN_FRONTEND</span><span class="o">=</span>noninteractive apt-get upgrade <span class="nt">-y</span>
</code></pre></div></div>

<h2 id="step-2-install-docker">Step 2: Install Docker</h2>

<p>Install Docker using the official convenience script, which sets up the Docker engine and the compose plugin together. Running Vaultwarden in a container keeps it isolated from the rest of the system, so upgrades and removal stay clean.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-fsSL</span> https://get.docker.com | sh
</code></pre></div></div>

<h2 id="step-3-write-the-compose-file">Step 3: Write the compose file</h2>

<p>Create a dedicated folder and write a compose file describing the Vaultwarden service. The key detail is binding the published port to 127.0.0.1, which keeps the service off the public internet. Your vault data is stored in a data folder beside the compose file, and sign-ups stay enabled for now so you can create your own account.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="nt">-p</span> /opt/vaultwarden/data
<span class="nb">cat</span> <span class="o">&gt;</span> /opt/vaultwarden/compose.yaml <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
services:
  vaultwarden:
    image: vaultwarden/server:latest
    container_name: vaultwarden
    restart: unless-stopped
    environment:
      - DOMAIN=http://localhost:8080
      - SIGNUPS_ALLOWED=true
    volumes:
      - ./data:/data
    ports:
      - "127.0.0.1:8080:80"
</span><span class="no">EOF
</span></code></pre></div></div>

<h2 id="step-4-start-vaultwarden">Step 4: Start Vaultwarden</h2>

<p>Start the container with docker compose, which pulls the image and runs it in the background. The restart policy in the compose file brings Vaultwarden back automatically after a server reboot.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /opt/vaultwarden <span class="o">&amp;&amp;</span> docker compose up <span class="nt">-d</span>
</code></pre></div></div>

<h2 id="step-5-open-the-ssh-tunnel">Step 5: Open the SSH tunnel</h2>

<p>Because the port is closed to the outside, you reach it through an SSH tunnel opened from your laptop, not from the server. The tunnel forwards a local port on your laptop (8080) to the server’s private port, and it only works while that terminal stays open.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">echo</span> <span class="s1">'On YOUR laptop run: ssh -N -L 8080:127.0.0.1:8080 root@YOUR_SERVER_IP  (leave it running)'</span>
</code></pre></div></div>

<h2 id="step-6-create-your-account">Step 6: Create your account</h2>

<p>With the tunnel active, open localhost on port 8080 in your laptop’s browser and create your account. Choose a strong master password and store it somewhere safe, because nobody, including the server admin, can recover it for you.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">echo</span> <span class="s1">'In your laptop browser open http://localhost:8080 , click Create account, use a strong master password.'</span>
</code></pre></div></div>

<h2 id="step-7-add-the-browser-extension">Step 7: Add the browser extension</h2>

<p>Install the Bitwarden browser extension and, before logging in, change its server URL to http://localhost:8080 so it connects to your server instead of the official cloud. Log in and save a test password to confirm everything works end to end.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">echo</span> <span class="s1">'Install the Bitwarden extension, set Server URL to http://localhost:8080 , log in, add a test password.'</span>
</code></pre></div></div>

<h2 id="step-8-schedule-daily-backups">Step 8: Schedule daily backups</h2>

<p>Install cron and add a small script that archives the data folder and keeps only the last fourteen days of backups. A cron entry runs it every night at 3 AM, and running it once by hand gives you a first backup immediately. Copy the archives off the server now and then, since a backup stored on the same machine won’t help if you lose that machine.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">DEBIAN_FRONTEND</span><span class="o">=</span>noninteractive apt-get <span class="nb">install</span> <span class="nt">-y</span> cron
<span class="nb">mkdir</span> <span class="nt">-p</span> /root/backups
<span class="nb">cat</span> <span class="o">&gt;</span> /usr/local/bin/vw-backup.sh <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
#!/bin/sh
tar czf /root/backups/vaultwarden-</span><span class="si">$(</span><span class="nb">date</span> +%F<span class="si">)</span><span class="sh">.tar.gz -C /opt/vaultwarden data
find /root/backups -name 'vaultwarden-*.tar.gz' -mtime +14 -delete
</span><span class="no">EOF
</span><span class="nb">chmod</span> +x /usr/local/bin/vw-backup.sh
<span class="nb">echo</span> <span class="s1">'0 3 * * * root /usr/local/bin/vw-backup.sh'</span> <span class="o">&gt;</span> /etc/cron.d/vaultwarden-backup
<span class="nb">chmod </span>644 /etc/cron.d/vaultwarden-backup
systemctl <span class="nb">enable</span> <span class="nt">--now</span> cron
/usr/local/bin/vw-backup.sh
</code></pre></div></div>

<h2 id="step-9-disable-public-sign-ups">Step 9: Disable public sign-ups</h2>

<p>Once your account exists, turn off public sign-ups by flipping the setting to false with a quick sed edit, then recreate the container with compose up. Your account and data stay intact, and nobody else can register on your server.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /opt/vaultwarden <span class="o">&amp;&amp;</span> <span class="nb">sed</span> <span class="nt">-i</span> <span class="s1">'s/SIGNUPS_ALLOWED=true/SIGNUPS_ALLOWED=false/'</span> compose.yaml <span class="o">&amp;&amp;</span> docker compose up <span class="nt">-d</span>
</code></pre></div></div>

<h2 id="common-mistakes">Common mistakes</h2>

<ul>
  <li>Closing the SSH tunnel terminal and then wondering why the extension or browser can’t connect. The tunnel must stay running whenever you sync, so reopen it (or set up a persistent tunnel) before logging in.</li>
  <li>Keeping backups only on the same VPS. If the server is lost or the disk fails, the backups go with it, so regularly copy the archives to another machine or storage location.</li>
  <li>Forgetting to disable sign-ups, or losing the master password. Leaving registration open invites strangers onto your server, and a lost master password cannot be reset, so store it safely offline.</li>
</ul>

<h2 id="wrap-up">Wrap-up</h2>

<p>You now have a private, self-hosted password manager that’s patched, backed up and closed to the public. Next, import your existing passwords, test restoring a backup so you know it works, and consider adding the mobile app through the same tunnel or a private network such as a VPN.</p>

<p>Every command here was tested on a fresh Ubuntu 24.04 server before publishing. Watch the full walkthrough on <a href="https://youtu.be/eMYS1ldxhh4">YouTube</a> — new tutorials every week on <strong>Lamplight Servers</strong>.</p>]]></content><author><name></name></author><category term="selfhosted" /><category term="docker" /><category term="vaultwarden" /><category term="linux" /><summary type="html"><![CDATA[Set up a private Vaultwarden server in Docker on a VPS, accessed over an SSH tunnel, with nightly backups and public sign-ups turned off.]]></summary></entry><entry><title type="html">Run Your Own Private Cloud: Nextcloud on Docker with Backups</title><link href="https://lamplightservers.github.io/run-your-own-private-cloud-nextcloud-on-docker-with-backups/" rel="alternate" type="text/html" title="Run Your Own Private Cloud: Nextcloud on Docker with Backups" /><published>2026-11-13T08:58:39+00:00</published><updated>2026-11-13T08:58:39+00:00</updated><id>https://lamplightservers.github.io/run-your-own-private-cloud-nextcloud-on-docker-with-backups</id><content type="html" xml:base="https://lamplightservers.github.io/run-your-own-private-cloud-nextcloud-on-docker-with-backups/"><![CDATA[<p>Cloud storage is convenient, but your files live on someone else’s servers, under someone else’s rules and pricing. Free tiers fill up quickly, and handing personal documents, photos and backups to a third party is a trade-off many developers would rather avoid.</p>

<p>In this guide we build a private Nextcloud backed by PostgreSQL, running in Docker on your own VPS. It restarts automatically after a reboot, stays off the public internet and is reached through an SSH tunnel. We also test file sync over WebDAV and set up a nightly backup job. Self-hosting gives you full control over your data, predictable costs and a setup you can fully understand and reproduce.</p>

<iframe width="100%" style="aspect-ratio:16/9" src="https://www.youtube-nocookie.com/embed/KgVJjIxZd6U" title="Video tutorial" frameborder="0" allowfullscreen=""></iframe>

<h2 id="what-you-need">What you need</h2>

<ul>
  <li>A VPS with Ubuntu 24.04 (2 vCPU / 4 GB RAM is plenty). I use <a href="https://www.vdsina.com/?partner=xuevxsn1ece5">VDSina</a> <em>(affiliate link — it supports the channel at no extra cost to you)</em>.</li>
  <li>An SSH connection to it (any terminal works).</li>
</ul>

<blockquote>
  <p>Short on time? Every command below is also in <a href="https://github.com/lamplightservers/lamplightservers.github.io/blob/main/scripts/run-your-own-private-cloud-nextcloud-on-docker-with-backups/install.sh">one ready-to-run script</a>.</p>
</blockquote>

<h2 id="step-1-update-the-system">Step 1: Update the system</h2>

<p>We start by updating the system packages so we’re building on a clean, current base. We also install cron, which the nightly backup needs later, and enable it so it starts on every boot.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">DEBIAN_FRONTEND</span><span class="o">=</span>noninteractive
apt-get update <span class="nt">-y</span>
apt-get upgrade <span class="nt">-y</span> <span class="nt">-o</span> Dpkg::Options::<span class="o">=</span><span class="nt">--force-confold</span>
apt-get <span class="nb">install</span> <span class="nt">-y</span> cron
systemctl <span class="nb">enable</span> <span class="nt">--now</span> cron
</code></pre></div></div>

<h2 id="step-2-install-docker">Step 2: Install Docker</h2>

<p>Next we install Docker with the official convenience script. It sets up the Docker engine and the Compose plugin, which lets us run Nextcloud and its database as containers instead of installing them by hand.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-fsSL</span> https://get.docker.com | sh
</code></pre></div></div>

<h2 id="step-3-generate-secrets-file">Step 3: Generate secrets file</h2>

<p>We create a project folder and a secrets file holding the database and admin passwords. The passwords are generated randomly with OpenSSL so they can’t be guessed, and the file permissions are tightened so only root can read it.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="nt">-p</span> /opt/nextcloud <span class="o">&amp;&amp;</span> <span class="nb">cd</span> /opt/nextcloud
<span class="nb">cat</span> <span class="o">&gt;</span> .env <span class="o">&lt;&lt;</span><span class="no">EOF</span><span class="sh">
DB_PASSWORD=</span><span class="si">$(</span>openssl rand <span class="nt">-hex</span> 16<span class="si">)</span><span class="sh">
NC_ADMIN_USER=admin
NC_ADMIN_PASSWORD=</span><span class="si">$(</span>openssl rand <span class="nt">-hex</span> 12<span class="si">)</span><span class="sh">
</span><span class="no">EOF
</span><span class="nb">chmod </span>600 .env
</code></pre></div></div>

<h2 id="step-4-write-the-compose-file">Step 4: Write the compose file</h2>

<p>The compose file defines two services, PostgreSQL and Nextcloud, both set to restart unless stopped so they return after a reboot. Nextcloud waits for the database health check before starting and listens only on localhost, so it isn’t exposed to the internet. A config check at the end confirms the file is valid.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /opt/nextcloud/docker-compose.yml <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
name: nextcloud
services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: </span><span class="k">${</span><span class="nv">DB_PASSWORD</span><span class="k">}</span><span class="sh">
    volumes:
      - db:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U nextcloud -d nextcloud"]
      interval: 5s
      timeout: 5s
      retries: 20
  app:
    image: nextcloud:apache
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "127.0.0.1:8080:80"
    environment:
      POSTGRES_HOST: db
      POSTGRES_DB: nextcloud
      POSTGRES_USER: nextcloud
      POSTGRES_PASSWORD: </span><span class="k">${</span><span class="nv">DB_PASSWORD</span><span class="k">}</span><span class="sh">
      NEXTCLOUD_ADMIN_USER: </span><span class="k">${</span><span class="nv">NC_ADMIN_USER</span><span class="k">}</span><span class="sh">
      NEXTCLOUD_ADMIN_PASSWORD: </span><span class="k">${</span><span class="nv">NC_ADMIN_PASSWORD</span><span class="k">}</span><span class="sh">
      NEXTCLOUD_TRUSTED_DOMAINS: localhost 127.0.0.1
    volumes:
      - app:/var/www/html
volumes:
  db:
  app:
</span><span class="no">EOF
</span><span class="nb">cd</span> /opt/nextcloud <span class="o">&amp;&amp;</span> docker compose config <span class="nt">-q</span> <span class="o">&amp;&amp;</span> <span class="nb">echo </span>compose-ok
</code></pre></div></div>

<h2 id="step-5-start-nextcloud-and-create-admin">Step 5: Start Nextcloud and create admin</h2>

<p>We bring everything up with docker compose. Docker pulls the images, starts the database, then starts Nextcloud, which creates the admin account on its first run. That first start can take a minute or two, so be patient.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cd</span> /opt/nextcloud <span class="o">&amp;&amp;</span> docker compose up <span class="nt">-d</span>
</code></pre></div></div>

<h2 id="step-6-show-login-and-phone-info">Step 6: Show login and phone info</h2>

<p>This step prints the login details. Since the port is bound to localhost, you open an SSH tunnel from your own computer and browse to localhost on port 8080 to sign in with the generated credentials. The phone app works the same way, but only through a tunnel or a VPN.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">.</span> /opt/nextcloud/.env
<span class="nv">IP</span><span class="o">=</span><span class="si">$(</span><span class="nb">hostname</span> <span class="nt">-I</span> | <span class="nb">awk</span> <span class="s1">'{print $1}'</span><span class="si">)</span>
<span class="nb">echo</span> <span class="s2">"Tunnel from your PC: ssh -N -L 8080:localhost:8080 root@</span><span class="nv">$IP</span><span class="s2">"</span>
<span class="nb">echo</span> <span class="s2">"Then open: http://localhost:8080"</span>
<span class="nb">echo</span> <span class="s2">"User: </span><span class="nv">$NC_ADMIN_USER</span><span class="s2">  Password: </span><span class="nv">$NC_ADMIN_PASSWORD</span><span class="s2">"</span>
<span class="nb">echo</span> <span class="s2">"Phone: install the official Nextcloud app (Google Play, F-Droid or App Store) and log in to this server."</span>
<span class="nb">echo</span> <span class="s2">"Note: a phone can only reach it through a tunnel or VPN, since port 8080 is bound to localhost only."</span>
</code></pre></div></div>

<h2 id="step-7-upload-and-verify-a-test-file">Step 7: Upload and verify a test file</h2>

<p>To test sync for real, we create a small text file and upload it over WebDAV, the same protocol sync clients use. If the command finishes without an error the upload worked, and the file shows up in the web interface.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">.</span> /opt/nextcloud/.env
<span class="nb">echo</span> <span class="s2">"Lamplight sync works"</span> <span class="o">&gt;</span> /tmp/test.txt
curl <span class="nt">-s</span> <span class="nt">-u</span> <span class="s2">"</span><span class="nv">$NC_ADMIN_USER</span><span class="s2">:</span><span class="nv">$NC_ADMIN_PASSWORD</span><span class="s2">"</span> <span class="nt">-T</span> /tmp/test.txt http://localhost:8080/remote.php/dav/files/<span class="nv">$NC_ADMIN_USER</span>/test.txt
</code></pre></div></div>

<h2 id="step-8-write-the-backup-script">Step 8: Write the backup script</h2>

<p>The backup script puts Nextcloud into maintenance mode, dumps the database and archives the files volume. It turns maintenance mode off again on exit, even if something fails, so the instance isn’t left locked. Backups older than seven days are deleted so the disk doesn’t fill up.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /usr/local/bin/nc-backup.sh <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
#!/bin/bash
set -e
B=/var/backups/nextcloud
D=</span><span class="si">$(</span><span class="nb">date</span> +%F-%H%M<span class="si">)</span><span class="sh">
mkdir -p "</span><span class="nv">$B</span><span class="sh">"
cd /opt/nextcloud
occ() { docker compose exec -T -u www-data app php occ "</span><span class="nv">$@</span><span class="sh">"; }
occ maintenance:mode --on
trap 'occ maintenance:mode --off' EXIT
docker compose exec -T db sh -c 'pg_dump -U "</span><span class="nv">$POSTGRES_USER</span><span class="sh">" "</span><span class="nv">$POSTGRES_DB</span><span class="sh">"' | gzip &gt; "</span><span class="nv">$B</span><span class="sh">/db-</span><span class="nv">$D</span><span class="sh">.sql.gz"
docker run --rm -v nextcloud_app:/data:ro -v "</span><span class="nv">$B</span><span class="sh">":/backup alpine tar czf "/backup/files-</span><span class="nv">$D</span><span class="sh">.tar.gz" -C /data .
find "</span><span class="nv">$B</span><span class="sh">" -type f -mtime +7 -delete
echo "backup </span><span class="nv">$D</span><span class="sh"> done"
</span><span class="no">EOF
</span><span class="nb">chmod</span> +x /usr/local/bin/nc-backup.sh
</code></pre></div></div>

<h2 id="step-9-schedule-nightly-backup">Step 9: Schedule nightly backup</h2>

<p>We schedule the script with a cron file so it runs every night at three o’clock. Its output goes to a log file, which lets you check later that it actually ran.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /etc/cron.d/nextcloud-backup <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
0 3 * * * root /usr/local/bin/nc-backup.sh &gt;&gt; /var/log/nc-backup.log 2&gt;&amp;1
</span><span class="no">EOF
</span><span class="nb">chmod </span>644 /etc/cron.d/nextcloud-backup
</code></pre></div></div>

<h2 id="step-10-run-backup-and-verify">Step 10: Run backup and verify</h2>

<p>Finally we run the backup by hand to prove it works. The listing should show a compressed database dump and a files archive. A backup you haven’t tested is just a hope, so never skip this check.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/usr/local/bin/nc-backup.sh <span class="o">&amp;&amp;</span> <span class="nb">ls</span> <span class="nt">-lh</span> /var/backups/nextcloud
</code></pre></div></div>

<h2 id="common-mistakes">Common mistakes</h2>

<ul>
  <li>Exposing the Nextcloud port publicly without HTTPS sends logins and files in plain text. Keep it bound to localhost and use an SSH tunnel or VPN, or put a properly configured TLS reverse proxy in front of it.</li>
  <li>Leaving the backups on the same server means a disk failure or a compromised VPS takes both the data and its copies. Regularly copy the archives to another machine or off-site storage.</li>
  <li>Losing or exposing the secrets file causes trouble either way. Keep it readable only by root, store a copy somewhere safe, and don’t commit it to Git, since the database password can’t easily be recovered.</li>
</ul>

<h2 id="wrap-up">Wrap-up</h2>

<p>Now that your Nextcloud is running and backed up, try restoring a backup on a test machine to be sure it works. Then add a domain with HTTPS, install the desktop and mobile sync clients, and consider off-site copies of your backups.</p>

<p>Every command here was tested on a fresh Ubuntu 24.04 server before publishing. Watch the full walkthrough on <a href="https://youtu.be/KgVJjIxZd6U">YouTube</a> — new tutorials every week on <strong>Lamplight Servers</strong>.</p>]]></content><author><name></name></author><category term="selfhosted" /><category term="docker" /><category term="nextcloud" /><category term="linux" /><summary type="html"><![CDATA[Set up a private Nextcloud with PostgreSQL in Docker on your VPS. Includes SSH tunnel access, WebDAV sync testing and a nightly cron backup.]]></summary></entry><entry><title type="html">Run n8n on Your Own VPS with Docker Compose: Persistent Setup</title><link href="https://lamplightservers.github.io/run-n8n-on-your-own-vps-with-docker-compose-persistent-setup/" rel="alternate" type="text/html" title="Run n8n on Your Own VPS with Docker Compose: Persistent Setup" /><published>2026-11-07T12:27:49+00:00</published><updated>2026-11-07T12:27:49+00:00</updated><id>https://lamplightservers.github.io/run-n8n-on-your-own-vps-with-docker-compose-persistent-setup</id><content type="html" xml:base="https://lamplightservers.github.io/run-n8n-on-your-own-vps-with-docker-compose-persistent-setup/"><![CDATA[<p>Cloud automation tools are convenient, but the bills grow with every workflow, and your data and credentials live on someone else’s servers. Setting up your own instance by hand can also be fiddly, especially when you want it to survive reboots and updates without losing anything.</p>

<p>In this guide we build a self-hosted n8n workflow automation server in Docker on a VPS. It has persistent storage, automatic restarts, an encrypted credential store, and a working health check on localhost. Self-hosting gives you full control over your data, no per-execution pricing, and a setup you can back up, move, or upgrade whenever you like.</p>

<iframe width="100%" style="aspect-ratio:16/9" src="https://www.youtube-nocookie.com/embed/k5du4Mumgqo" title="Video tutorial" frameborder="0" allowfullscreen=""></iframe>

<h2 id="what-you-need">What you need</h2>

<ul>
  <li>A VPS with Ubuntu 24.04 (2 vCPU / 4 GB RAM is plenty). I use <a href="https://www.vdsina.com/?partner=xuevxsn1ece5">VDSina</a> <em>(affiliate link — it supports the channel at no extra cost to you)</em>.</li>
  <li>An SSH connection to it (any terminal works).</li>
</ul>

<blockquote>
  <p>Short on time? Every command below is also in <a href="https://github.com/lamplightservers/lamplightservers.github.io/blob/main/scripts/run-n8n-on-your-own-vps-with-docker-compose-persistent-setup/install.sh">one ready-to-run script</a>.</p>
</blockquote>

<h2 id="step-1-install-docker">Step 1: Install Docker</h2>

<p>Docker’s official install script sets up Docker Engine and the Compose plugin in one pass. Running it non-interactively means it won’t pause for prompts, which makes the setup repeatable and easy to paste into a fresh server.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-fsSL</span> https://get.docker.com | <span class="nv">DEBIAN_FRONTEND</span><span class="o">=</span>noninteractive sh
</code></pre></div></div>

<h2 id="step-2-enable-the-firewall">Step 2: Enable the firewall</h2>

<p>The firewall is configured so that SSH on port 22 is allowed before anything else. This order matters, because enabling the firewall without that rule could cut off your own connection. The force flag skips the confirmation question so the command runs straight through.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ufw allow 22/tcp <span class="o">&amp;&amp;</span> ufw <span class="nt">--force</span> <span class="nb">enable</span>
</code></pre></div></div>

<h2 id="step-3-generate-encryption-key">Step 3: Generate encryption key</h2>

<p>n8n encrypts the credentials you store in it, using a secret encryption key. We create a project folder, generate a random 64-character key with OpenSSL, and save it in a .env file. Restricting that file to root with chmod keeps the key private. Back it up somewhere safe, since without it saved credentials can’t be decrypted.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">mkdir</span> <span class="nt">-p</span> /opt/n8n
<span class="nb">echo</span> <span class="s2">"N8N_ENCRYPTION_KEY=</span><span class="si">$(</span>openssl rand <span class="nt">-hex</span> 32<span class="si">)</span><span class="s2">"</span> <span class="o">&gt;</span> /opt/n8n/.env
<span class="nb">chmod </span>600 /opt/n8n/.env
</code></pre></div></div>

<h2 id="step-4-create-compose-file">Step 4: Create compose file</h2>

<p>The compose file pulls the official n8n image and uses a restart policy that brings it back after crashes or reboots unless you stop it yourself. The port is bound to 127.0.0.1, so n8n stays private to the server rather than exposed to the internet. A named volume stores workflows and data outside the container so they survive replacement. Quoting the EOF marker prevents the shell from expanding the key, so Compose reads it from the .env file instead.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">cat</span> <span class="o">&gt;</span> /opt/n8n/compose.yaml <span class="o">&lt;&lt;</span><span class="sh">'</span><span class="no">EOF</span><span class="sh">'
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n:latest
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_HOST=localhost
      - N8N_PORT=5678
      - N8N_PROTOCOL=http
      - N8N_SECURE_COOKIE=false
      - GENERIC_TIMEZONE=UTC
      - TZ=UTC
      - N8N_ENCRYPTION_KEY=</span><span class="k">${</span><span class="nv">N8N_ENCRYPTION_KEY</span><span class="k">}</span><span class="sh">
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  n8n_data:
</span><span class="no">EOF
</span></code></pre></div></div>

<h2 id="step-5-start-n8n">Step 5: Start n8n</h2>

<p>Docker Compose downloads the image and starts n8n in the background. The first run takes longer because the image has to be pulled, and later starts are much faster.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker compose <span class="nt">-f</span> /opt/n8n/compose.yaml up <span class="nt">-d</span>
</code></pre></div></div>

<h2 id="step-6-wait-for-n8n">Step 6: Wait for n8n</h2>

<p>Viewing the last few lines of the container logs shows how startup is going. You’re waiting for a line saying the editor is accessible, which means n8n has finished initializing and is ready to serve requests.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker compose <span class="nt">-f</span> /opt/n8n/compose.yaml logs <span class="nt">--tail</span> 5 n8n
</code></pre></div></div>

<h2 id="step-7-test-the-web-interface">Step 7: Test the web interface</h2>

<p>A curl request to the local web interface, printing only the HTTP status code, makes a quick health check. A 200 response confirms that n8n is running and answering on localhost.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>curl <span class="nt">-s</span> <span class="nt">-o</span> /dev/null <span class="nt">-w</span> <span class="s1">'HTTP %{http_code}\n'</span> http://127.0.0.1:5678/
</code></pre></div></div>

<h2 id="common-mistakes">Common mistakes</h2>

<ul>
  <li>Losing or changing the encryption key. If the .env file is deleted or the key is regenerated, existing credentials become unreadable. Store a copy in a password manager and generate the key only once.</li>
  <li>Enabling the firewall before allowing SSH. This can lock you out of the VPS entirely. Always add the port 22 rule first, and if you use a custom SSH port, allow that one instead.</li>
  <li>Expecting to reach n8n from the internet after binding to 127.0.0.1. The binding is deliberate for safety, so the editor is only reachable from the server itself. To use it remotely, put a reverse proxy with HTTPS in front or use an SSH tunnel, rather than opening the port directly.</li>
</ul>

<h2 id="wrap-up">Wrap-up</h2>

<p>Next, put a reverse proxy such as Caddy or Nginx in front of n8n with a domain and HTTPS so you can reach the editor securely from anywhere. After that, set up regular backups of the data volume and your .env file, then start building your first workflows.</p>

<p>Every command here was tested on a fresh Ubuntu 24.04 server before publishing. Watch the full walkthrough on <a href="https://youtu.be/k5du4Mumgqo">YouTube</a> — new tutorials every week on <strong>Lamplight Servers</strong>.</p>]]></content><author><name></name></author><category term="selfhosted" /><category term="docker" /><category term="n8n" /><category term="automation" /><summary type="html"><![CDATA[Set up a self-hosted n8n server on a VPS with Docker and Compose. Includes persistent storage, auto-restart, a firewall, and a localhost health check.]]></summary></entry></feed>