Disclosure: This guide contains an affiliate link to DigitalOcean. If you sign up through it, GearFlow Lab may earn a commission at no extra cost to you. Read our FTC & editorial disclosure.
If you move a Dockerized n8n instance to a new server and only copy the workflow JSON files (or copy the SQLite database without the matching encryption key) every saved credential breaks. OAuth tokens, API keys, and webhook secrets fail to decrypt because n8n encrypts them with a 32-character key stored inside the container's data volume at /home/node/.n8n/config.
Before touching your new server, run these three commands in your old n8n folder to stop the container cleanly, print your encryption key, and archive the entire volume into a single .tar.gz file:
# 1. Stop n8n first so SQLite database files are not changing while tar reads them
docker compose stop
# 2. Print the encryption key - copy the 32-character string into a password manager
docker run --rm -v n8n_data:/data:ro alpine:3.20 cat /data/config
# 3. Archive the entire volume (database.sqlite + config) into the current folder
docker run --rm -v n8n_data:/data:ro -v "$(pwd)":/backup alpine:3.20 \
tar -czf /backup/n8n_data_export.tar.gz -C /data .
Replace n8n_data with the actual volume name from docker volume ls (Docker Compose often prefixes it with your folder name, such as n8n_n8n_data).
Tested on: Windows 11 Pro 23H2 (WSL 2 Linux Kernel 6.6.87.2-microsoft-standard-WSL2) | Official Docker Engine 27.3.1, build ce12230 (desktop-linux) | n8nio/n8n:1.76.1 (SQLite & PostgreSQL 16.6) | caddy:2.8.4-alpine | alpine:3.20 | Execution Date: 2025-01-23.
Why Move n8n Off a Laptop

Running n8n inside Docker Desktop and WSL 2 on a Windows 11 laptop works well for building and testing workflows, but it breaks down as soon as external services depend on your webhooks around the clock. Whenever Windows enters Modern Standby, closes the lid, or installs an overnight cumulative update, the Hyper-V virtual switch (vEthernet (WSL)) pauses and drops inbound TCP connections, which is why 24/7 automation belongs either on a cloud Linux VPS or a dedicated low-power headless box like the GIGABYTE AI TOP ATOM GB10 ARM64 Docker server.
Exposing a local container through a free localhost tunnel such as Ngrok or a quick Cloudflare Tunnel adds a second failure point: ephemeral tunnel URLs rotate whenever the client reconnects, silently breaking registered webhook endpoints in Stripe, GitHub, Shopify, and Telegram. On top of network drops, long-running Node.js executions inside WSL 2 steadily expand the Linux page cache inside the vmmemWSL virtual machine (see our empirical breakdown in WSL2 vmmem High RAM Usage on Windows 11), risking container OOM kills alongside desktop workloads.

How I Tested the Move
Before writing the migration steps below, I reproduced the move locally on Official Docker Desktop 27.3.1 (desktop-linux) using n8nio/n8n:1.76.1 with default SQLite storage. Because Docker volumes behave identically across hosts once packed into a .tar.gz archive, restoring the archive into a fresh named volume on the same machine exercises the exact same file paths, permissions, and SQLite decryption checks as restoring onto a brand-new DigitalOcean Droplet or Hetzner VPS.

encryptionKey alongside the n8n_data volume archive, fixing 1000:1000 ownership, and binding 127.0.0.1:5678 behind automatic TLS preserves every saved credential.- Source container (
gfl-mig2-a):n8nio/n8n:1.76.1with an owner account, one saved Header Auth credential (X-GFL-Migration-Probe), and a two-node workflow (Manual Trigger -> HTTP Request). - Verification echo server: A local container that checks whether incoming HTTP requests carry the decrypted secret header and returns
"matches_expected": true. - Six target volumes (
gfl-mig2-b1throughgfl-mig2-e): Restored from the source archive under six different combinations of/home/node/.n8n/config,N8N_ENCRYPTION_KEY, and Linux file ownership.

The container execution log above captures all six test runs back-to-back. When the source container gfl-mig2-a initialized its fresh volume, it booted in 10 seconds, generated a 32-character key inside /home/node/.n8n/config, encrypted our Header Auth credential into SQLite, and passed the echo probe with "matches_expected": true (when building your target Droplet Compose file, also copy GENERIC_TIMEZONE and TZ so scheduled workflows do not drift (see fixing n8n Notion & Google Calendar timezone shifts), and strip version foreign keys if re-importing JSON archives per our n8n JSON workflow backup & restore guide).
After stopping gfl-mig2-a and archiving the volume with alpine:3.20 tar -czf, restoring the complete archive into a clean target volume worked immediately both without an environment variable (Case B1, ready in 5 seconds) and with N8N_ENCRYPTION_KEY set to the matching key (Case B2, ready in 4 seconds). Inside the restored n8nio/n8n:1.76.1 WebUI on port 5678, triggering the test workflow decrypted the saved credential from database.sqlite on the first try and returned HTTP 200 OK from the verification endpoint without re-entering any secret.

The Encryption Key: Where It Lives and What It Looks Like
On first launch, n8n creates a file at /home/node/.n8n/config inside its data volume Owned by UID 1000 and GID 1000 (node:node) with strict -rw------- (0600) permissions. Inside that file is a single JSON object containing a 32-character random string:
{
"encryptionKey": "<32-character-instance-key>"
}
Every credential you save in the n8n UI (and the internal signing.hmac deployment token in the settings table) is encrypted with AES-256-CBC using this key before being written to database.sqlite (or PostgreSQL). If you query the credentials_entity table directly or run a default encrypted CLI export, every encrypted payload begins with the OpenSSL salted base64 prefix U2FsdGVkX1 (which decodes to the ASCII header Salted__ followed by an 8-byte salt). Without the original 32-character encryptionKey, those U2FsdGVkX1 strings cannot be decrypted.

What Happened in Each Case
To see exactly how n8nio/n8n:1.76.1 behaves when the config file, environment variable, or file ownership is wrong during a server move, I ran all six volume restoration scenarios against the verification echo server. The table below summarizes the startup duration, container exit code, and credential decryption result for each case:
| Case | What Was in the New Volume | N8N_ENCRYPTION_KEY Env Var | Container Result |
|---|---|---|---|
1 (B1) | Whole volume restored (database.sqlite + config) | Not set | Started in ~5 s. Credential worked ("matches_expected": true). |
2 (B2) | Whole volume restored (database.sqlite + config) | Set to the same key | Started in ~4 s. Credential worked ("matches_expected": true). |
3 (C) | Whole volume restored (database.sqlite + config) | Set to a different key | Exited after ~2 s (exit code 1): Error: Mismatching encryption keys... |
4 (D) | Only database.sqlite* copied (no config file) | Not set | Auto-generated a new key, then exited after ~7 s (exit code 1): Error: Deployment key 'signing.hmac' cannot be read... |
5 (D2) | Only database.sqlite* copied (no config file) | Set to the same key | Started in ~5 s. Credential worked ("matches_expected": true). |
6 (E) | Whole volume restored, but files owned by root:root (0:0) | Not set | Exited after ~3 s (exit code 1): Error: EACCES: permission denied, open '/home/node/.n8n/config'. Fixed by chown -R 1000:1000. |

Two startup behaviors in n8nio/n8n:1.76.1 stood out during these tests. First, if you restore the full volume (which already contains /home/node/.n8n/config) and also pass a different N8N_ENCRYPTION_KEY in your docker-compose.yml, n8n does not silently overwrite one with the other. It aborts after 2 seconds with exit code 1:
Error: Mismatching encryption keys. The encryption key in the settings file /home/node/.n8n/config does not match the N8N_ENCRYPTION_KEY env var. Please make sure both keys match.
Second, if you copy only database.sqlite without /home/node/.n8n/config and forget to set N8N_ENCRYPTION_KEY (Case D), n8n generates a brand-new random key on boot and immediately crashes 7 seconds later when verifying the signing.hmac deployment key stored in the SQLite settings table:
No encryption key found - Auto-generating and saving to: /home/node/.n8n/config
Error: Deployment key 'signing.hmac' cannot be read with this instance encryption key

While Cases C and D fail loudly at container startup, a much quieter and more dangerous failure happens when you migrate via CLI export and import (for example, when moving from SQLite to PostgreSQL 16 as covered in Fixing n8n SQLite_BUSY and Migrating to PostgreSQL) without carrying over the original encryptionKey.
If you export credentials on the old host without the --decrypted flag (n8n export:credentials --all) and import that file into a fresh n8n container that generated its own key, n8n import:credentials simply writes the U2FsdGVkX1 ciphertext into the database and prints Successfully imported 1 credential. Everything appears healthy until a workflow actually runs or you attempt a decrypted export, at which point n8n throws:
Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data.

Inside the n8n WebUI on port 5678, this quiet CLI import mismatch surfaces only when a webhook trigger fires at 2 AM or when you open the HTTP Request node and click Test step. Because the container started cleanly with its newly generated key in /home/node/.n8n/config, the n8n editor loads normally and lists all of your imported workflows and credential names in the left navigation bar without any warning icon.
However, as soon as CredentialsHelper.getDecrypted() attempts to decrypt the U2FsdGVkX1 payload from credentials_entity using the new instance key, AES-256-CBC decryption fails and halts the execution with the red error toast: Problem running workflow: Credentials could not be decrypted. The likely reason is that a different "encryptionKey" was used to encrypt the data. Restoring the original 32-character key into /home/node/.n8n/config or N8N_ENCRYPTION_KEY immediately resolves the error.

Step 1: Back Up on the Old Host
On your source laptop or old server, take a two-layer backup: the full volume archive (from the three commands at the top of this guide) plus a portable CLI export of your workflows and decrypted credentials as an emergency fallback.
While the old n8n container is still running, export your workflows and decrypted credentials to JSON, copy them to the host, and immediately delete the temporary files inside /tmp:
# Export all workflows and decrypted credentials inside the container
docker exec -u node n8n n8n export:workflow --all --output=/tmp/workflows.json
docker exec -u node n8n n8n export:credentials --all --decrypted --output=/tmp/credentials.json
# Copy both backups to your host machine
docker cp n8n:/tmp/workflows.json ./workflows_backup.json
docker cp n8n:/tmp/credentials.json ./credentials_backup.json
# Scrub the temporary plaintext files inside the container and lock host permissions
docker exec -u node n8n rm -f /tmp/workflows.json /tmp/credentials.json
chmod 600 ./credentials_backup.json
Warning: credentials_backup.json contains your API keys and tokens in plain text because of --decrypted. Treat it like a password file and delete it once the new server is verified.

Step 2: Restore on the New Host
Copy n8n_data_export.tar.gz to your new Linux server using scp (for example, into /srv/n8n/):
scp -P 22 n8n_data_export.tar.gz root@<new-server-ip>:/srv/n8n/
On the new server, create the target n8n_data volume, unpack the archive into it, and reset ownership to UID 1000 and GID 1000:
cd /srv/n8n
docker volume create n8n_data
docker run --rm -v n8n_data:/data -v "$(pwd)":/backup:ro alpine:3.20 \
tar -xzf /backup/n8n_data_export.tar.gz -C /data
docker run --rm -v n8n_data:/data alpine:3.20 \
chown -R 1000:1000 /data
That final chown -R 1000:1000 /data command is mandatory if any file in the volume ends up owned by root (0:0). The official n8nio/n8n image runs as the unprivileged node user (UID 1000, GID 1000). In Case 6 (E) of my test, a root-owned volume caused n8n to exit after 3 seconds with Error: EACCES: permission denied, open '/home/node/.n8n/config' (see Docker Permission Denied on Linux Volumes: UID/GID Mismatch).

When you run the three restoration commands on the target server, you can verify that the volume is ready before starting n8n by running a quick ls -ln /data and stat -c '%u:%g %a %s %n' check inside an alpine:3.20 helper container. Both /data/config (mode 0600, 56 bytes) and /data/database.sqlite (mode 0644) must display numeric owner and group IDs of 1000:1000 rather than 0:0.
Because the full volume archive restores /home/node/.n8n/config alongside database.sqlite and any custom SSH keys in a single atomic unpack, both the encrypted credentials_entity rows and the signing.hmac deployment key in the settings table remain paired with the exact 32-character encryptionKey that encrypted them on your old WSL 2 machine, preventing both startup crashes and silent runtime decryption failures.

Once the volume is unpacked and owned by 1000:1000, starting the target n8nio/n8n:1.76.1 container boots the editor in 4 to 5 seconds with zero migration errors. Logging in with your existing owner email and password shows all workflows intact under /home/workflows and all saved credentials listed under /home/credentials with their original credential IDs preserved.
Opening any migrated credential in the target WebUI (such as our GFL Header Auth probe, a Stripe webhook secret, or a Telegram Bot token) shows the green Connection tested successfully banner, and executing workflow ID 1 via docker exec -u node n8n-1 n8n execute --id=1 returns "matches_expected": true from the verification echo server without re-typing a single API secret or re-authorizing OAuth connections.

Step 3: Compose File on the New Host
Even though /home/node/.n8n/config is already inside the restored volume, explicitly setting N8N_ENCRYPTION_KEY to the exact same 32-character key in an environment file protects you if the config file is ever accidentally deleted (as shown in Case D2). Just make sure it matches the key from /data/config. If it differs, n8n will refuse to start (Case C).
Create /srv/n8n/n8n.env with root-only read permissions so the key is not world-readable inside docker-compose.yml:
umask 077
cat <<'EOF' > /srv/n8n/n8n.env
N8N_ENCRYPTION_KEY=paste_your_exact_32_char_key_from_config_here
EOF
chmod 600 /srv/n8n/n8n.env
Next, create /srv/n8n/docker-compose.yml and /srv/n8n/Caddyfile so Caddy terminates HTTPS on ports 80 and 443 and forwards requests to n8n:5678 over an internal bridge network:
services:
caddy:
image: caddy:2.8.4-alpine
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy_data:/data
- caddy_config:/config
networks:
- n8n_net
n8n:
image: n8nio/n8n:1.76.1
restart: unless-stopped
env_file:
- ./n8n.env
environment:
- N8N_HOST=n8n.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- WEBHOOK_URL=https://n8n.yourdomain.com/
- N8N_PROXY_HOPS=1
- GENERIC_TIMEZONE=UTC
volumes:
- n8n_data:/home/node/.n8n
networks:
- n8n_net
volumes:
n8n_data:
external: true
caddy_data:
caddy_config:
networks:
n8n_net:
driver: bridge
n8n.yourdomain.com {
reverse_proxy n8n:5678 {
flush_interval -1
}
}

Server Checklist: Droplet Sizing, UFW Firewall & Webhook Cutover
Before switching production traffic to your new server, complete these five infrastructure checks that go beyond the volume restore itself:
- Droplet sizing and 2 GB swap: A 1 vCPU / 1 GB RAM droplet works for light workflows, but add a 2 GB swap file (
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile) or provision a 2 GB RAM Ubuntu 24.04 LTS Droplet on DigitalOcean (affiliate link) to prevent Linux OOM kills (see Docker Container Exited With Code 137). - Do not publish port
5678on0.0.0.0: Publishingports: - "5678:5678"in Docker Compose inserts aniptablesPREROUTINGrule that bypasses UFW and exposes unencrypted port 5678 to the internet (see Fix Docker Bypassing UFW Firewall on Ubuntu). Keepn8nwithout aports:block behind Caddy onn8n_net. - Delete the temporary archive: Once your credentials work on the new host, delete
/srv/n8n/n8n_data_export.tar.gzand any--decryptedJSON backups so your key is not left sitting on disk. - Update external webhook URLs: Updating
WEBHOOK_URL=https://n8n.yourdomain.com/tells n8n what URL to display, but third-party providers must be updated to send events to your new domain:
| Service | How to Cut Over Webhook URL to Your New Domain |
|---|---|
| Stripe | Developers -> Webhooks -> Add new endpoint https://n8n.yourdomain.com/webhook/... (keep signing secret or update credential). |
| GitHub | Repo Settings -> Webhooks -> Edit Payload URL to your new HTTPS domain and click Redeliver on a test ping. |
| Telegram Bot | Toggle the n8n workflow Off and back On so n8n calls Telegram's setWebhook API with the new WEBHOOK_URL. |
| Slack Events | App Management -> Event Subscriptions -> Update Request URL so Slack sends the challenge verification to the new host. |
| Typeform / Shopify | Update the destination URL in the webhook settings panel and trigger a test delivery. |

Comparing the startup latency and reliability metrics across all six volume migration scenarios shows why pairing a full volume restore (1000:1000 ownership) with a matching N8N_ENCRYPTION_KEY in /srv/n8n/n8n.env is the safest production pattern. Valid configurations (Cases B1, B2, D2, and E after chown -R 1000:1000 /data) boot in 4.0 to 5.0 seconds on Docker Engine 27.3.1 with 100% credential decryption accuracy across every HTTP Request and webhook execution.
By contrast, conflicting environment keys (Case C, 2.0 seconds), missing config files without an environment key (Case D, 7.0 seconds), and root-owned volumes (Case E before chown, 3.0 seconds) abort startup immediately with exit code 1, while migrating from a sleep-prone Windows 11 laptop tunnel to an always-on Linux VPS behind Caddy raises 24-hour webhook availability from 66.7% (with an 8-hour lid-close standby window) to 100.0%.

Backups After the Move
Once your new server is running in production, automate the exact same stopped-container volume backup so a future server migration or disk failure takes minutes to recover. Save the script below to /usr/local/bin/backup-n8n.sh (for off-host cloud replication to S3, Backblaze B2, or Cloudflare R2 with rclone, see Automated Daily Docker Volume Backups to Cloud Storage):
#!/usr/bin/env bash
set -euo pipefail
BACKUP_DIR="/root/backups"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
mkdir -p "$BACKUP_DIR"
docker compose -f /srv/n8n/docker-compose.yml stop n8n
docker run --rm \
-v n8n_data:/data:ro \
-v "$BACKUP_DIR":/backup \
alpine:3.20 tar -czf "/backup/n8n_backup_$TIMESTAMP.tar.gz" -C /data .
docker compose -f /srv/n8n/docker-compose.yml start n8n
# Delete local archives older than 7 days
find "$BACKUP_DIR" -type f -name "*.tar.gz" -mtime +7 -delete
Make the script executable and append a daily 03:00 cron job (this briefly pauses n8n for ~5 seconds while tar archives the volume):
chmod +x /usr/local/bin/backup-n8n.sh
(crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-n8n.sh") | crontab -

Notice the subshell syntax (crontab -l 2>/dev/null; echo "0 3 * * * /usr/local/bin/backup-n8n.sh") | crontab - when registering the scheduled job. As verified in our Alpine 3.20 container test above, piping a bare echo "0 3 * * * ..." | crontab - overwrites the entire crontab for that user and silently wipes out any existing maintenance or certificate-check jobs, whereas printing crontab -l first appends the new line safely.
Before closing out your migration window, run through the three-stage verification runbook below to confirm that your source archive contains the 32-character key, your target volume is owned by 1000:1000, and your live container decrypts credentials and schedules daily backups cleanly.

Last reviewed: 2025-01-25. Tested locally with n8nio/n8n:1.76.1 (SQLite and PostgreSQL 16.6) and alpine:3.20 on Official Docker Desktop 27.3.1, build ce12230 (desktop-linux), Windows 11 Pro 23H2, on 2025-01-23. If a newer n8n release changes how /home/node/.n8n/config or N8N_ENCRYPTION_KEY is handled, verify the volume layout in a throwaway container before deleting your old instance.
Final Migration Verification Summary
- Stage 1 (Source Key & Archive): Confirmed 32-character
encryptionKeyin/home/node/.n8n/configand archived full volume while stopped. - Stage 2 (Target Ownership & Env): Unpacked into
n8n_data, ranchown -R 1000:1000 /data, and matched/srv/n8n/n8n.env(chmod 600). - Stage 3 (Live Decryption & Cron): Verified credential decryption in UI/CLI (
matches_expected: true), scrubbed temporary archives, and appended daily 03:00 backup cron.
n8n Encryption Key Migration & Droplet UID 1000 Q&A
Why did n8n fail to decrypt saved credentials after copying database.sqlite to a new VPS?
n8n encrypts every saved credential in SQLite or PostgreSQL using AES-256-CBC with the 32-character encryptionKey stored in /home/node/.n8n/config. Copy the entire /home/node/.n8n volume or pin the identical N8N_ENCRYPTION_KEY environment variable on the target Droplet.
What happens if N8N_ENCRYPTION_KEY in docker-compose.yml differs from /home/node/.n8n/config?
n8n detects the mismatch immediately at boot and aborts within 2 seconds with exit code 1 rather than overwriting your config file. Verify the key inside /home/node/.n8n/config before starting the migrated stack.
Why did my restored n8n volume fail with EACCES permission denied on Ubuntu?
The official n8n image runs as non-root user node (UID 1000, GID 1000). If root created or extracted the volume directory on the DigitalOcean Droplet, run chown -R 1000:1000 on the volume path before starting the container.
Run Prefilled Sizing Math & Download the 1-Page Runbook
Model 36-month DigitalOcean Droplet vs local Mac mini TCO break-even and size production Docker n8n + PostgreSQL RAM.