Skip to content

Deploying Memos (open-source flowed-notes) on AlmaLinux 9 with PostgreSQL + OIDC SSO

Stand up a hardened Memos server on AlmaLinux 9 — PostgreSQL backend, OIDC SSO against your IdP, persistent attachments, nginx + Let's Encrypt.

You stand up Memos in five minutes with docker run -p 5230:5230 -v ~/.memos:/var/opt/memos neosmemo/memos:stable because that’s the quickstart. The team starts dropping daily standups, Friday retros, and one-line “remember to ask about X” memos. Three months later you discover the resource: the SQLite file under ~/.memos has grown to 9 GB because every memo carries embedded image attachments, the host port :5230 is open to the internet because the install never put nginx in front, anyone with the URL can sign in because OIDC was never wired up, and the only “backup” is whatever the VM snapshot grabs while SQLite is mid-write. Memos is a great open-source flowed-notes tool for engineering teams — but the docker run from the README is a demo, not a deployment.

What’s happening

Memos (usememos/memos) supports a real persistence layer if you ask for it. The default driver is SQLite because that’s what the maintainers want a first-time user to see working. For a team archive, switch to PostgreSQL — Memos uses bun as its ORM and supports --driver postgres with a DSN. The same is true for storage: attachments default to the local filesystem under the data directory, but you can switch to S3-compatible storage if you operate one. The other capability the team will discover six weeks in is OIDC SSO. Memos calls it “Identity Providers” in System Settings and supports any OIDC-compliant IdP (Authentik, Keycloak, Zitadel, Google Workspace, Microsoft Entra). Once OIDC is on you can disable local password sign-up entirely — every account is provisioned via your IdP and de-provisioning happens by removing the user from the IdP group. The host should not publish :5230 directly; nginx terminates TLS, and Let’s Encrypt handles the certificate.

The mistakes that put a self-hosted Memos in a bad state are: SQLite chosen by accident (write-locked under concurrent edits), the data directory left under the user home (uncovered by VM-level backup), local sign-up still enabled after OIDC is configured (users have two ways to authenticate — one of them goes through your IdP, the other doesn’t), the MEMOS_PUBLIC=true flag set without realising it makes every memo world-readable, and no nginx rate limit on /api/v1/auth/sign-in so OIDC failures can be brute-forced from the open internet.

How to verify

After install, the host exposes only :443 (and :22). Postgres on 5432 must not appear:

ss -lntp | grep -E ':(80|443|5230|5432)\b'
# 0.0.0.0:443  nginx
# 127.0.0.1:5230  memos (via compose)

Memos should respond to its health probe over HTTPS:

curl -sS https://memos.example.com/healthz
# {"status":"ok"}

OIDC should be the only sign-in path once you’ve configured it:

curl -sS https://memos.example.com/api/v1/workspace/profile | jq .disallowSignup
# true

If disallowSignup returns false, local registration is still on and anyone reaching the URL can create an account. Flip it under System Settings → Workspace before going live.

The fix

Save the script as /root/setup-memos-almalinux9.sh and run it on a clean AlmaLinux 9 VM. It installs everything: base hardening (SELinux enforcing, firewalld with HTTP/HTTPS only, fail2ban, dnf-automatic, SSH key-only with root key preserved), Docker CE + compose plugin, the Memos container pinned to a release tag, PostgreSQL 16 kept on the internal compose network with a strong generated password, all secrets persisted to /opt/memos/.env with chmod 600, attachments directory on /var/lib/memos/data (so VM-level backups capture every uploaded image), nginx as the TLS terminator with a rate-limited /api/v1/auth/ location, Let’s Encrypt via certbot, and a listener-wait loop. OIDC wiring lives in the Memos UI under System Settings → Identity Providers (you can’t configure it via env vars in the current release) and the script prints the exact callback URL you’ll register with your IdP.

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

### AlmaLinux 9 Memos clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs Docker + Memos + PostgreSQL + nginx + Let's Encrypt
### Local sign-up should be disabled once OIDC is configured (System Settings -> Workspace)
### No local backups; assumes VM-level backup of /var/lib/memos and the pg volume
### Reboot remains manual

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

: "${MEMOS_DOMAIN:?Set MEMOS_DOMAIN=memos.example.com}"
: "${MEMOS_EMAIL:?Set MEMOS_EMAIL=ops@example.com for Let's Encrypt}"
MEMOS_VERSION="${MEMOS_VERSION:-0.24.4}"
MEMOS_PG_PASSWORD="${MEMOS_PG_PASSWORD:-$(openssl rand -hex 24)}"

echo
echo "========================================"
echo "Memos AlmaLinux 9 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
dnf -y update
dnf -y install epel-release

echo "==> Installing base packages"
dnf -y install \
  vim curl wget chrony fail2ban dnf-automatic \
  policycoreutils-python-utils lsof tcpdump bind-utils tar gzip \
  iproute net-tools openssl jq socat firewalld

systemctl enable --now chronyd

echo "==> SELinux enforcing"
sed -i 's/^SELINUX=.*/SELINUX=enforcing/' /etc/selinux/config
setenforce 1 || true

echo "==> Kernel/sysctl tuning"
cat > /etc/sysctl.d/99-memos.conf <<'SYSCTL'
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
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
sysctl --system

cat > /etc/security/limits.d/99-memos.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS

echo "==> Configuring firewalld"
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

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

set_sshd_option() {
  local key="$1"
  local 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 ChallengeResponseAuthentication 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 sshd

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 "==> dnf-automatic"
cat > /etc/dnf/automatic.conf <<'DNFAUTO'
[commands]
upgrade_type = security
random_sleep = 900
download_updates = yes
apply_updates = yes
[emitters]
emit_via = stdio
DNFAUTO
systemctl enable --now dnf-automatic.timer

echo "==> Installing Docker CE"
dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker

echo "==> Preparing /opt/memos and /var/lib/memos"
mkdir -p /opt/memos /var/lib/memos/data
chmod 700 /opt/memos /var/lib/memos
chown -R 1000:1000 /var/lib/memos/data

cat > /opt/memos/.env <<ENV
MEMOS_VERSION=${MEMOS_VERSION}
MEMOS_DOMAIN=${MEMOS_DOMAIN}
PG_PASSWORD=${MEMOS_PG_PASSWORD}
ENV

chmod 600 /opt/memos/.env

cat > /opt/memos/docker-compose.yml <<'COMPOSE'
services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: memos
      POSTGRES_PASSWORD: ${PG_PASSWORD}
      POSTGRES_DB: memos
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U memos -d memos"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 20s

  memos:
    image: neosmemo/memos:${MEMOS_VERSION}
    restart: unless-stopped
    depends_on:
      db:
        condition: service_healthy
    environment:
      MEMOS_DRIVER: postgres
      MEMOS_DSN: "postgresql://memos:${PG_PASSWORD}@db:5432/memos?sslmode=disable"
      MEMOS_MODE: prod
      MEMOS_PORT: "5230"
      MEMOS_PUBLIC: "false"
    volumes:
      - /var/lib/memos/data:/var/opt/memos
    ports:
      - "127.0.0.1:5230:5230"

volumes:
  pgdata:
    driver: local
COMPOSE

echo "==> Starting Memos stack"
docker compose --env-file /opt/memos/.env -f /opt/memos/docker-compose.yml up -d

echo "==> Waiting for Memos on 127.0.0.1:5230"
for i in {1..120}; do
  if curl -fs http://127.0.0.1:5230/healthz >/dev/null 2>&1; then
    break
  fi
  sleep 2
done

if ! curl -fs http://127.0.0.1:5230/healthz >/dev/null 2>&1; then
  echo "Memos failed to come up on 127.0.0.1:5230"
  docker compose -f /opt/memos/docker-compose.yml logs --tail=200 memos || true
  exit 1
fi

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

cat > /etc/nginx/conf.d/memos.conf <<NGINX
upstream memos_backend {
    server 127.0.0.1:5230;
    keepalive 32;
}

limit_req_zone \$binary_remote_addr zone=memos_auth:10m rate=10r/m;

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

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

    client_max_body_size 50M;
    proxy_read_timeout   300s;
    proxy_send_timeout   300s;

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

    location /api/v1/auth/ {
        limit_req zone=memos_auth burst=5 nodelay;
        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_pass http://memos_backend;
    }

    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_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_pass http://memos_backend;
    }
}
NGINX

# Allow nginx to talk to the local Memos port under SELinux
setsebool -P httpd_can_network_connect 1

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

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${MEMOS_EMAIL}" -d "${MEMOS_DOMAIN}" --redirect

systemctl enable --now certbot-renew.timer 2>/dev/null || 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"
dnf -y update

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r

echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|5230|5432)\b' || true

echo
echo "Containers:"
docker compose -f /opt/memos/docker-compose.yml ps

echo
echo "Services:"
systemctl is-active docker nginx fail2ban chronyd || true

echo
echo "Healthcheck over HTTPS:"
curl -sS https://${MEMOS_DOMAIN}/healthz || true

echo
echo "Web UI:"
echo "https://${MEMOS_DOMAIN}/"

echo
echo "Configure OIDC SSO:"
echo "1. Sign in as the first admin account via the web UI."
echo "2. System Settings -> Identity Providers -> New OAuth2 Provider"
echo "3. In your IdP (Authentik, Keycloak, etc.) register a client:"
echo "   Redirect URI:  https://${MEMOS_DOMAIN}/auth/callback"
echo "4. Paste the IdP client id, client secret, auth/token/userinfo URLs."
echo "5. System Settings -> Workspace -> 'Disable user sign-up' = ON."
echo "6. Test: open an incognito window, click 'Sign in with OIDC'; the local sign-up form should be hidden."
echo
echo "Data paths covered by VM-level backup:"
echo "  /var/lib/memos/data  (attachments + uploaded blobs)"
echo "  docker volume pgdata (memos table data)"

Make it executable and run it:

chmod 700 /root/setup-memos-almalinux9.sh
MEMOS_DOMAIN=memos.example.com \
MEMOS_EMAIL=ops@example.com \
/root/setup-memos-almalinux9.sh

The first account you create at https://memos.example.com/ becomes the admin. Go straight to System Settings → Identity Providers and register a new OAuth2 provider against your IdP using the callback URL https://memos.example.com/auth/callback; for Authentik or Keycloak this is a five-field form. Once the round-trip works, go to System Settings → Workspace and turn off local sign-up — from then on every new user comes through the IdP and de-provisioning happens by removing the user from the IdP group. Confirm /var/lib/memos/data is in the VM-level backup scope: that’s where every uploaded image lands, and Postgres tells you what memo references which file but not what the file actually contained.

Stack Harbor operates self-hosted Memos under environment management — patching, monitoring, backup verification, and Sev-1 escalation through the support desk, with cloud compute provisioned to fit your team’s archive size. Plan a scoping call if you’d like us to take it over.