Skip to content

Deploying CryptPad encrypted collaboration on Ubuntu 22.04 (production-ready)

Stand up a hardened CryptPad on Ubuntu 22.04 — main and sandbox domains, persistent data volume, nginx + Let's Encrypt, locked-down registration.

You roll out CryptPad because the legal team wants encrypted shared notes and the product team wants real-time pads that don’t leave the perimeter. The Docker quickstart works, three people sign up, the first pad is created. Six months later, the instance is on a single domain (the sandbox iframe has been disabled with a “fix” that wired it to the same hostname), registration is wide open so the Tuesday standup roster includes two unknown accounts from the public internet, the persistent data volume sits in /tmp because nobody changed the default, and the TLS certificate hasn’t renewed because nginx was hand-edited after certbot ran. Nothing is encrypted at rest the way the brochure promised because the deployment never actually had two domains.

What’s happening

CryptPad’s threat model rests on two hostnames. The main hostname serves the application; the sandbox hostname serves the document iframes from a different origin so the rendered content cannot reach the encryption keys held in the parent frame. Collapse those into one origin and the same-origin policy disappears — every “encrypted” pad is one XSS away from leaking its symmetric key. The data volume lives at /cryptpad/data and holds every pad, every account blob, every channel log; persisted between deploys, covered by VM-level backup. Registration must be allowed-list controlled via restrictRegistration: true and a manual admin invite, otherwise anyone with the URL becomes a tenant. Nginx terminates TLS and proxies websockets — the upgrade headers matter or real-time editing degrades to “save and refresh”. The CSP block in application_config.js is fragile; don’t hand-edit it without reading customize.dist/application_config.js first.

How to verify

Both hostnames must serve :443, and only :443 and :22 on the host:

ss -lntp | grep -E ':(80|443|3000|3001|3003)\b'
# 0.0.0.0:443  nginx
# 127.0.0.1:3000  cryptpad http
# 127.0.0.1:3001  cryptpad ws
# 127.0.0.1:3003  cryptpad admin

Sandbox isolation — the sandbox response must include a strict CSP and a different host:

curl -sS -D - -o /dev/null https://sandbox.cryptpad.example.com/ | grep -iE '^(content-security-policy|host)'

Registration closure — the admin endpoint should refuse anonymous signups:

curl -sS -o /dev/null -w '%{http_code}\n' \
  -X POST https://cryptpad.example.com/api/profile
# 401 or 403

If the sandbox CSP is missing or the registration POST returns 200 for a random body, the install is not production-ready — fix it before the first invite.

The fix

Save the script below as /root/setup-cryptpad-ubuntu22.sh, then run it. It installs CryptPad on a fresh Ubuntu 22.04 VM under a non-root service user, with the main and sandbox domains on separate certificates, the persistent data volume at /cryptpad/data, registration locked to admin invite, nginx terminating TLS with the upgrade headers required for websockets, and certbot bound to a renewal hook that reloads nginx.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 CryptPad clean VM installer
### Two domains: main + sandbox (REQUIRED for E2EE isolation)
### Persistent data volume at /cryptpad/data
### Registration locked; admin must invite manually
### No local backups; assumes VM-level backup

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${CRYPTPAD_MAIN_DOMAIN:?Set CRYPTPAD_MAIN_DOMAIN=cryptpad.example.com}"
: "${CRYPTPAD_SANDBOX_DOMAIN:?Set CRYPTPAD_SANDBOX_DOMAIN=sandbox.cryptpad.example.com}"
: "${CRYPTPAD_EMAIL:?Set CRYPTPAD_EMAIL=ops@example.com for Let's Encrypt}"
CRYPTPAD_VERSION="${CRYPTPAD_VERSION:-2024.12.0}"
CRYPTPAD_USER="${CRYPTPAD_USER:-cryptpad}"
CRYPTPAD_HOME="${CRYPTPAD_HOME:-/cryptpad}"

echo
echo "========================================"
echo "CryptPad Ubuntu 22.04 Setup"
echo "========================================"
echo "Main:    ${CRYPTPAD_MAIN_DOMAIN}"
echo "Sandbox: ${CRYPTPAD_SANDBOX_DOMAIN}"
echo

if [[ "${CRYPTPAD_MAIN_DOMAIN}" == "${CRYPTPAD_SANDBOX_DOMAIN}" ]]; then
  echo "Main and sandbox domains must differ. Aborting."
  exit 1
fi

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 git \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq build-essential \
  software-properties-common

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-cryptpad.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
vm.max_map_count = 262144
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

cat > /etc/security/limits.d/99-cryptpad.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
${CRYPTPAD_USER} soft nofile 64000
${CRYPTPAD_USER} hard nofile 64000
LIMITS

echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1" value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart ssh

echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN

systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Installing Node.js 20 via NodeSource"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get -y install nodejs

echo "==> Creating cryptpad service user"
if ! id "${CRYPTPAD_USER}" >/dev/null 2>&1; then
  useradd --system --home-dir "${CRYPTPAD_HOME}" --shell /usr/sbin/nologin "${CRYPTPAD_USER}"
fi
mkdir -p "${CRYPTPAD_HOME}/data" "${CRYPTPAD_HOME}/blob" "${CRYPTPAD_HOME}/blobstage" \
         "${CRYPTPAD_HOME}/datastore" "${CRYPTPAD_HOME}/block" "${CRYPTPAD_HOME}/customize"
chown -R "${CRYPTPAD_USER}:${CRYPTPAD_USER}" "${CRYPTPAD_HOME}"

echo "==> Cloning CryptPad ${CRYPTPAD_VERSION}"
sudo -u "${CRYPTPAD_USER}" git clone https://github.com/cryptpad/cryptpad.git "${CRYPTPAD_HOME}/src"
cd "${CRYPTPAD_HOME}/src"
sudo -u "${CRYPTPAD_USER}" git checkout "${CRYPTPAD_VERSION}"

echo "==> Installing CryptPad dependencies"
sudo -u "${CRYPTPAD_USER}" npm ci --omit=dev
sudo -u "${CRYPTPAD_USER}" npm run install:components

echo "==> Writing config.js (main + sandbox + locked registration)"
cat > "${CRYPTPAD_HOME}/src/config/config.js" <<EOF
/* CryptPad production config */
module.exports = {
    httpUnsafeOrigin: 'https://${CRYPTPAD_MAIN_DOMAIN}',
    httpSafeOrigin:   'https://${CRYPTPAD_SANDBOX_DOMAIN}',
    httpAddress: '127.0.0.1',
    httpPort: 3000,
    websocketPath: '/cryptpad_websocket',
    adminEmail: '${CRYPTPAD_EMAIL}',
    adminKeys: [],
    inactiveTime: 90,
    archiveRetentionTime: 30,
    accountRetentionTime: -1,
    maxUploadSize: 50 * 1024 * 1024,
    premiumUploadSize: 150 * 1024 * 1024,
    enableEmbedding: false,
    logToStdout: false,
    logLevel: 'info',
    logFeedback: false,
    verbose: false,
    installMethod: 'unspecified',
    filePath: './datastore/',
    archivePath: './data/archive',
    pinPath: './data/pins',
    taskPath: './data/tasks',
    blockPath: './block',
    blobPath: './blob',
    blobStagingPath: './blobstage',
    decreePath: './data/decrees',
    logPath: './data/logs',
    restrictRegistration: true,
    restrictSsoRegistration: true,
    disableIntegratedTasks: false,
    disableIntegratedEviction: true,
    enforceMFA: true
};
EOF
chown "${CRYPTPAD_USER}:${CRYPTPAD_USER}" "${CRYPTPAD_HOME}/src/config/config.js"
chmod 600 "${CRYPTPAD_HOME}/src/config/config.js"

echo "==> Customize directory (preserves overrides across upgrades)"
sudo -u "${CRYPTPAD_USER}" cp -a "${CRYPTPAD_HOME}/src/customize.dist/." "${CRYPTPAD_HOME}/customize/"
ln -sfn "${CRYPTPAD_HOME}/customize" "${CRYPTPAD_HOME}/src/customize"

echo "==> systemd unit"
cat > /etc/systemd/system/cryptpad.service <<UNIT
[Unit]
Description=CryptPad — encrypted collaboration suite
After=network.target

[Service]
Type=simple
User=${CRYPTPAD_USER}
Group=${CRYPTPAD_USER}
WorkingDirectory=${CRYPTPAD_HOME}/src
ExecStart=/usr/bin/node ${CRYPTPAD_HOME}/src/server.js
Restart=on-failure
RestartSec=5
LimitNOFILE=64000
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
ReadWritePaths=${CRYPTPAD_HOME}
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
UNIT

systemctl daemon-reload
systemctl enable --now cryptpad

echo "==> Waiting for CryptPad on 127.0.0.1:3000"
for i in {1..120}; do
  if ss -lntp | grep -q '127.0.0.1:3000'; then break; fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:3000'; then
  echo "CryptPad failed to listen on 127.0.0.1:3000"
  journalctl -u cryptpad --no-pager -n 200 || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/cryptpad <<NGINX
map \$http_upgrade \$connection_upgrade {
    default upgrade;
    ''      close;
}

upstream cryptpad_main {
    server 127.0.0.1:3000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${CRYPTPAD_MAIN_DOMAIN} ${CRYPTPAD_SANDBOX_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${CRYPTPAD_MAIN_DOMAIN};

    client_max_body_size 150M;
    proxy_read_timeout   600s;
    proxy_send_timeout   600s;
    proxy_connect_timeout 60s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location /cryptpad_websocket {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_http_version 1.1;
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection \$connection_upgrade;
        proxy_pass http://cryptpad_main;
        proxy_read_timeout 3600s;
    }

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_http_version 1.1;
        proxy_pass http://cryptpad_main;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${CRYPTPAD_SANDBOX_DOMAIN};

    client_max_body_size 150M;
    proxy_read_timeout   600s;
    proxy_send_timeout   600s;
    proxy_connect_timeout 60s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_http_version 1.1;
        proxy_pass http://cryptpad_main;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificates (main + sandbox)"
certbot --nginx --non-interactive --agree-tos \
  -m "${CRYPTPAD_EMAIL}" \
  -d "${CRYPTPAD_MAIN_DOMAIN}" \
  -d "${CRYPTPAD_SANDBOX_DOMAIN}" \
  --redirect

systemctl enable --now certbot.timer

echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
  if ss -lntp | grep -q ':443'; then break; fi
  sleep 1
done

echo "==> Final package update"
apt-get -y upgrade

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000|3001|3003)\b' || true

echo
echo "Service:"
systemctl is-active cryptpad nginx fail2ban chrony || true

echo
echo "Sandbox isolation check (expect CSP header on sandbox response):"
curl -sS -D - -o /dev/null "https://${CRYPTPAD_SANDBOX_DOMAIN}/" | grep -iE 'content-security-policy' || true

echo
echo "Registration check (expect non-200 on profile POST without keys):"
curl -sS -o /dev/null -w '%{http_code}\n' -X POST "https://${CRYPTPAD_MAIN_DOMAIN}/api/profile" || true

echo
echo "Web UI: https://${CRYPTPAD_MAIN_DOMAIN}/"
echo
echo "First steps:"
echo "1. Register the first account from a browser on the main domain."
echo "2. Note its public signing key (Settings -> Account -> public key)."
echo "3. Add the key to adminKeys in ${CRYPTPAD_HOME}/src/config/config.js then 'systemctl reload cryptpad'."
echo "4. Visit /admin/ to invite the rest of the team via signed invite links."
echo "5. Confirm the persistent data volume at ${CRYPTPAD_HOME}/data is covered by your VM-level backup."

Make it executable and run it:

chmod 700 /root/setup-cryptpad-ubuntu22.sh
CRYPTPAD_MAIN_DOMAIN=cryptpad.example.com \
CRYPTPAD_SANDBOX_DOMAIN=sandbox.cryptpad.example.com \
CRYPTPAD_EMAIL=ops@example.com \
/root/setup-cryptpad-ubuntu22.sh

The first account that registers on the main domain becomes the seed identity — copy its public signing key into the adminKeys array in /cryptpad/src/config/config.js, reload the service, and use /admin/ to invite the rest of the team. Don’t open restrictRegistration. Confirm the sandbox domain has its own TLS certificate and that the CSP response header is present on the sandbox origin only; without that header the encryption isolation is gone. Make sure VM-level backup covers /cryptpad/data, /cryptpad/blob, /cryptpad/datastore, and /cryptpad/block — those four directories are the entire state of the instance.

Run the production CryptPad on Stack Harbor’s managed cloud compute with patching, monitoring, and Sev-1 escalation in place: Cloud compute — or start the conversation if you’d like us to plan the migration.