What is Vaultwarden?

Vaultwarden is a lightweight, self-hosted password manager server that is fully compatible with official Bitwarden client apps and browser extensions. It acts as a secure digital vault to store, generate, and organize credentials.

To ensure zero-knowledge privacy, all vault data is encrypted locally on the user's device using AES-256-CBC with HMAC-SHA256 authentication before being sent to the server. Bitwarden clients communicate with the Vaultwarden backend over a secure connection using Transport Layer Security (TLS/HTTPS).

Installation

Create a Vaultwarden directory:

Terminal
mkdir -p ~/docker/vaultwarden

Move to the Vaultwarden directory:

Terminal
cd ~/docker/vaultwarden

Create the Docker compose file:

Terminal
nano docker-compose.yml

Add the following:

services:
    vaultwarden:
        image: vaultwarden/server:latest
        container_name: vaultwarden
        restart: unless-stopped

    security_opt:
        - no-new-privileges:true

    ports:
        - 127.0.0.1:8080:80

    volumes:
        - ./vw-data:/data

    environment:
        SIGNUPS_ALLOWED: "true"
        WEBSOCKET_ENABLED: "true"

Press CTRL+O to save the file, then press CTRL+X to close.

Start Vaultwarden:

Terminal
docker compose up -d

If you are not already running a reverse proxy, install Caddy:

Terminal
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl

Download and install the Caddy GPG key:

Terminal
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

Add the Caddy software repository:

Terminal
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

Update packages:

Terminal
sudo apt update

Install Caddy:

Terminal
sudo apt install caddy -y

Create a certificate directory:

Terminal
sudo mkdir -p /etc/caddy/certs

Generate a certificate:

Terminal
sudo openssl req -x509 -nodes -days 3650 \
-newkey rsa:4096 \
-keyout /etc/caddy/certs/vaultwarden.key \
-out /etc/caddy/certs/vaultwarden.crt

Configure Caddy:

Terminal
sudo nano /etc/caddy/Caddyfile

Add these lines, replacing server-ip with your server IP address:

https://server-ip {

    tls /etc/caddy/certs/vaultwarden.crt /etc/caddy/certs/vaultwarden.key

    reverse_proxy 127.0.0.1:8080
}

Press CTRL+O to save the file, then press CTRL+X to close.

Set ownership of the certificate directory:

Terminal
sudo chown -R caddy:caddy /etc/caddy/certs

Correct the permissions:

Terminal
sudo chmod 750 /etc/caddy/certs
sudo chmod 640 /etc/caddy/certs/vaultwarden.crt
sudo chmod 640 /etc/caddy/certs/vaultwarden.key

Restart Caddy:

Terminal
sudo systemctl restart caddy

Add a firewall rule to allow traffic on port 443 from your local subnet:

Terminal
sudo ufw allow from 10.64.20.0/24 to any port 443 proto tcp

Confirm everything is working by accessing Vaultwarden in your browser, replacing server-ip with your server's IP address:

https://server-ip/

Click on Create account.

Follow the setup prompts.


Hardening

Now that your account has been created, disable new signups:

Terminal
nano docker-compose.yml

Change SIGNUPS_ALLOWED to false:

      SIGNUPS_ALLOWED: "false"

Press CTRL+O to save the file, then press CTRL+X to close.

Restart Vaultwarden:

Terminal
docker compose up -d

Verify Vaultwarden is running:

Terminal
docker ps

Create an update automation script:

Terminal
sudo nano /usr/local/bin/vaultwarden-updates.sh

Add the below text, replacing user-name with the appropriate value:

#!/bin/bash

docker pull vaultwarden/server:latest

docker stop vaultwarden
docker rm vaultwarden

docker run -d \
    --name vaultwarden \
    --restart unless-stopped \
    --security-opt no-new-privileges:true \
    -p 127.0.0.1:8080:80 \
    -v /home/werehoosier/docker/vaultwarden/vw-data:/data \
    vaultwarden/server:latest

docker image prune -f

Press CTRL+O to save the file, then press CTRL+X to close.

Make the script executable:

Terminal
sudo chmod +x /usr/local/bin/vaultwarden-updates.sh

Test the script:

Terminal
sudo /usr/local/bin/vaultwarden-updates.sh

Schedule the script to run daily by adding a cron job:

Terminal
sudo crontab -e

Add the following lines:

# Vaultwarden Updates
15 4 * * * /usr/local/bin/vaultwarden-updates.sh >> /var/log/vaultwarden-updates.log 2>&1

The update log can be checked by running the command:

Terminal
sudo cat /var/log/vaultwarden-updates.log

Connecting to Bitwarden Extension

View the certificate on your server:

Terminal
sudo cat /etc/caddy/certs/vaultwarden.crt

Copy the entire certificate.

Create a file on your local machine with the filename vaultwarden.crt.

Paste the certificate.

Save vaultwarden.crt.

If on Windows, click on the Start menu.

Open Manage Computer Certificates.

Expand Trusted Root Certification Authorities.

Right-click on Certificates.

Expand All Tasks.

Click on Import.

Follow the prompts to import vaultwarden.crt.

Open your web browser.

Install the Bitwarden browser extension if it is not already installed.

Click on the extension icon in your browser.

On the login page, click the Accessing dropdown near the bottom.

Select self-hosted.

Enter your server IP address as the Server URL.

Click on Save.

Log in using the credentials set up previously.


Loading...