Home Blog

Self-hosting Vaultwarden on a small VPS

Vaultwarden is a Rust reimplementation of the Bitwarden server API, small enough to run comfortably on a 2 vCPU box alongside other services. It inherits Bitwarden's client-side encryption: the master password never reaches the server, the vault key is derived on the device, and the server only ever stores ciphertext plus a KDF-derived hash. A full server breach does not hand over your passwords.

Client-side encryption was a reason I felt comfortable running it myself. I still needed to consider how the clients were delivered, how updates worked, and how I would recover the data.

The deployment

services:
  vaultwarden:
    image: vaultwarden/server:1.37.1
    container_name: vaultwarden
    restart: unless-stopped
    ports:
      # Loopback only; nginx terminates TLS and proxies to it.
      - "127.0.0.1:8082:80"
    volumes:
      - ./vaultwarden-data:/data
    environment:
      # Must match the public URL exactly or the clients break.
      - DOMAIN=https://vault.example.com
      - SIGNUPS_ALLOWED=false
      - SHOW_PASSWORD_HINT=false
      - WEB_VAULT_ENABLED=false

No ADMIN_TOKEN, so the admin panel does not exist. One fewer credential to leak on a box that is reachable from the internet.

nginx in front needs two things beyond the usual proxy headers: client_max_body_size 128m for attachments and full exports, and WebSocket upgrade headers, because /notifications/hub is how clients learn about changes made elsewhere. Without the upgrade headers, everything works except live sync, which is a confusing thing to debug later.

Do not put HTTP basic auth in front of it. The browser extension and mobile clients cannot answer that prompt.

Verifying that signups are closed

Set SIGNUPS_ALLOWED=false to close registration. I checked all three registration paths because their responses differ.

V=https://vault.example.com

curl -s -X POST "$V/identity/accounts/register" \
  -H 'Content-Type: application/json' \
  --data '{"email":"[email protected]","name":"p","masterPasswordHash":"x","key":"x","kdf":0,"kdfIterations":600000}'

curl -s -X POST "$V/identity/accounts/register/send-verification-email" \
  -H 'Content-Type: application/json' --data '{"email":"[email protected]","name":"p"}'

Both return Registration not allowed or user already exists. The third, /identity/accounts/register/finish, returns Registration is missing required parameters for a payload it cannot deserialise. That is a validation error raised before the signup check, so on its own it tells you nothing about whether signups are open. Reading the source, it delegates to the same register() handler that enforces CONFIG.is_signup_allowed(&email), so it is covered.

The check that settles it regardless of endpoint semantics:

sqlite3 /path/to/vaultwarden-data/db.sqlite3 'SELECT email FROM users;'

One more wrinkle: the web vault UI keeps showing a "Create account" link even with signups closed. It is cosmetic. The server refuses.

Turning off the web vault

I disabled the web vault because it serves client code from the same host that stores the encrypted data.

The threat model of client-side encryption assumes the client is trustworthy. The browser extension and desktop apps ship their own code; they never download it from your server. The web vault does. So if someone gets code execution on your box, they can modify the JavaScript it serves and capture your master password the next time you log in through a browser. That converts a server compromise, which the encryption model is designed to survive, into total vault compromise.

- WEB_VAULT_ENABLED=false

After recreating the container, the root path is gone but the API is untouched:

GET /                                      404
GET /alive                                 200
GET /api/config                            200
POST /identity/accounts/prelogin/password  200
POST /identity/connect/token   (bad pw)     400

I checked for a 404 on / and a 200 on /alive. The extensions and installed clients continued working. The tradeoff is losing browser access from a machine without a client installed.

A client-server version mismatch

The main login problem turned out to be a client-server version mismatch.

The Firefox extension refused to log in with “an unexpected error has occurred.” The certificate chain verified successfully, /alive and /api/config returned 200, prelogin returned the expected KDF parameters, and connect/token rejected a deliberately wrong password. Those checks did not reveal the failing request.

The server log had the answer immediately:

POST /identity/accounts/prelogin/password  =>  404 Not Found

Current Bitwarden clients call /identity/accounts/prelogin/password as the first step of login. The version I had pinned did not implement that route. It 404s, and the client surfaces that as a generic error with no indication of which request failed.

The server log identified the missing route much more clearly than the extension’s error message.

I had pinned the server image and left it behind while the browser and phone clients updated through their stores. Eventually a client expected an API route that my server did not provide. I need to keep the server compatible with those clients, rather than treating the image pin as a substitute for reviewing updates.

Since schema migrations are one-way, back up before upgrading:

sqlite3 vaultwarden-data/db.sqlite3 ".backup '/tmp/vw.sqlite3'"
tar czf /path/to/backups/vaultwarden-manual-$(date -u +%Y%m%dT%H%M%SZ).tar.gz \
    -C /path/to vaultwarden-data
# then bump the tag, docker compose pull && up -d, and check:
docker logs vaultwarden 2>&1 | grep -iE 'error|panic|migrat'
sqlite3 vaultwarden-data/db.sqlite3 'SELECT COUNT(*) FROM ciphers;'

Two things about backups

My backups need to account for the live SQLite database and the signing key.

Use sqlite3 .backup. The database runs in WAL mode; when I checked, there was a live 247 KB db.sqlite3-wal beside it. Copying only the main file can miss committed data in that WAL. .backup produces a consistent copy without stopping the service.

Include rsa_key.pem. It signs the JWTs. Restoring without it logs out the existing clients.

And encrypt the backup before it leaves the machine. The vault items are already encrypted client-side, but the database also contains the master password hash, which is offline-crackable. That should not sit unencrypted in someone else's object storage.

Current configuration

Setting State
signups closed, verified against all three endpoints
web vault off
admin panel disabled, no token set
2FA TOTP enabled
KDF PBKDF2-SHA256, 600,000 iterations
exposure loopback only, nginx with TLS 1.2/1.3 and HSTS

I still plan to switch the KDF to Argon2id, a client-side change that makes GPU password cracking more expensive than PBKDF2. TOTP does not help against offline attacks on a stolen database; that protection depends on the master password and KDF. TOTP protects online login attempts.

Is it safe?

Cryptographically, self-hosted and hosted Bitwarden are the same design. What differs is who runs it. The hosted service has a security team, audits, DDoS absorption and reliable backups.

For most people, the hosted service is likely to be safer in practice because it handles patching and recovery. My own gaps were operational: I had delayed updates and had not set up backups. Running it myself means taking responsibility for both.