SaferComputing.com

Reference · Self-hosted services

n8n on port 5678: claim the owner account, back up the encryption key, keep Execute Command blocked

A new n8n instance gives its owner account to whoever signs up first. Check port 5678 and the owner, back up the encryption key in .n8n/config, keep the default NODES_EXCLUDE entries and keep /metrics private.

Published
Last checked
Applies to
Self-hosted n8n 2.x in Docker or installed with npm on Linux; tested on n8n 2.46.7
Technical specification
Target artifactThe n8n editor and REST API on TCP port 5678, its owner account, the encryption key in .n8n/config, and the NODES_EXCLUDE and N8N_METRICS environment variables.
Default behaviourn8n listens on ::, every address; a new instance shows a signup screen and its first user becomes the owner; the key is generated on first start; n8n 2.0 and later block Execute Command and Local File Trigger; /metrics is off.
Safe statePort 5678 on 127.0.0.1 behind an HTTPS proxy, or reached over a private network; an owner you created; a copy of the key off the server; NODES_EXCLUDE unset, or a list that keeps both default entries; /metrics off or private.
Check on Linuxsudo ss -tlnp | grep ':5678'
Check in n8ncurl -s http://127.0.0.1:5678/rest/settings | grep -o '"showSetupOnFirstLoad":[a-z]*'
Check in Dockerdocker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' n8n | grep -E '^(NODES_EXCLUDE|N8N_METRICS)='
Check from another devicenc -vz -w 5 SERVER_IP 5678
Fix in Dockerpublish with -p 127.0.0.1:5678:5678, or "127.0.0.1:5678:5678" in the Compose ports: list
Fix for blocked nodeskeep "n8n-nodes-base.executeCommand" and "n8n-nodes-base.localFileTrigger" in any NODES_EXCLUDE list you set
Fix for the keydocker cp n8n:/home/node/.n8n/config ./n8n-config-backup.json, then move the copy off the server

Read the result

ResultMeaning
127.0.0.1:5678Only this computer can connect
*:5678 or [::]:5678Every address: n8n's default outside Docker
0.0.0.0:5678 owned by docker-proxyPublished by Docker on every IPv4 address, whatever UFW says
"showSetupOnFirstLoad":trueNo owner yet: the next person to finish the signup screen becomes the owner
A NODES_EXCLUDE= lineIt replaces the default list; check that both default entries are in it
N8N_METRICS=true/metrics answers without a sign-in

The Docker checks use the container name n8n; docker ps shows yours.

Claim the owner account before the port is reachable

The first account created on the signup screen becomes the owner, with every permission on the instance. The form posts to /rest/owner/setup, which needs no sign-in until an owner exists and then answers Instance owner already setup. In n8n 2.46.7 the screen has no time limit.

  1. Start n8n with port 5678 on 127.0.0.1 only, as in Port 5678 and Docker.
  2. Open a tunnel from your laptop and complete the signup at http://127.0.0.1:5678:
Your laptop
ssh -N -L 5678:127.0.0.1:5678 USER@SERVER
  1. Once the check shows "showSetupOnFirstLoad":false, put n8n behind its HTTPS proxy.

If the check shows false and you did not create the owner, someone else did. Remove the container and its data volume, and start again with the port on 127.0.0.1.

Create the owner from environment variables (n8n 2.17.0 and later)

With N8N_INSTANCE_OWNER_MANAGED_BY_ENV=true, n8n creates the owner at start-up from N8N_INSTANCE_OWNER_EMAIL, N8N_INSTANCE_OWNER_FIRST_NAME, N8N_INSTANCE_OWNER_LAST_NAME and N8N_INSTANCE_OWNER_PASSWORD_HASH. The password must be a bcrypt hash; n8n's documentation warns that a plain-text password breaks sign-in.

Ubuntu, after sudo apt install python3-bcrypt
python3 -c 'import bcrypt, getpass; print(bcrypt.hashpw(getpass.getpass().encode(), bcrypt.gensalt()).decode())'

In a Compose file, write each $ in the hash as $$: Compose reads $ as the start of a variable and replaces an unset one with an empty string.

Back up the encryption key

n8n encrypts the credentials it saves, such as API keys for other services, with a key it generates on first start and keeps in the file config in its .n8n folder: /home/node/.n8n/config in the official Docker image, ~/.n8n/config for an npm install. If you set N8N_ENCRYPTION_KEY, that value is the key, and it must match the file.

Without the key, the saved credentials cannot be decrypted; in a test with n8n 2.46.7, a new key against the old database stopped n8n at start-up. Keep the copy off the server and guard it like a password: with the key and the database, anyone can decrypt every credential.

Linux, as a user in the docker group
docker cp n8n:/home/node/.n8n/config ./n8n-config-backup.json

The copy keeps the file's owner-only permissions. Move it to your own computer, then delete it from the server. For an npm install, copy ~/.n8n/config instead. In queue mode, every worker needs the same key in N8N_ENCRYPTION_KEY.

NODES_EXCLUDE replaces the default list

Since n8n 2.0, NODES_EXCLUDE defaults to ["n8n-nodes-base.executeCommand", "n8n-nodes-base.localFileTrigger"]. The Execute Command node runs shell commands on the machine that runs n8n, or inside the n8n container under Docker; n8n's 2.0 notes say both nodes are disabled by default "because they pose security risks".

A value you set replaces that list. Tested on n8n 2.46.7:

NODES_EXCLUDEResult
Not setExecute Command, its AI tool version and Local File Trigger are blocked
[]Every node is available, as n8n's documentation says
["n8n-nodes-base.readWriteFile"]Read/Write Files from Disk is blocked; Execute Command and Local File Trigger are back
n8n-nodes-base.readWriteFile, not a JSON listRead as empty: every node is available, with no warning in the log

To block more nodes, start from the two defaults:

Line in docker-compose.yml, under environment:
      - NODES_EXCLUDE=["n8n-nodes-base.executeCommand","n8n-nodes-base.localFileTrigger","n8n-nodes-base.readWriteFile"]

n8n reads the list at start-up: recreate the container with docker compose up -d, then repeat the Docker check.

Keep /metrics private

N8N_METRICS=true turns on a Prometheus endpoint at /metrics that needs no sign-in. In a test with n8n 2.46.7 it answered an anonymous request with 176 metric lines, including the exact n8n and Node.js versions. n8n's documentation says to expose it only to internal services that consume the data, and not on the public internet, because it can reveal sensitive operational data.

Linux, on the n8n host
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:5678/metrics

200 means the endpoint is on; 404 means it is off.

Port 5678 and Docker

N8N_LISTEN_ADDRESS defaults to ::, every address. In Docker, -p 5678:5678 makes the port available to the outside world, and Docker routes that traffic before UFW's rules apply: see Docker published ports bypass UFW. n8n's own Compose example publishes "127.0.0.1:5678:5678" behind Traefik for HTTPS.

In Docker, change the publish address, not N8N_LISTEN_ADDRESS: in a test, a server listening on 127.0.0.1 inside its container could not be reached through its published port. For an npm install, set N8N_LISTEN_ADDRESS=127.0.0.1; the log then shows n8n ready on 127.0.0.1, port 5678. For remote use, use the SSH tunnel above or a private interface.

Troubleshooting

Mismatching encryption keys at start-up

N8N_ENCRYPTION_KEY differs from the key in .n8n/config. Set it to the key in the file, or remove it so n8n uses the file.

Deployment key 'signing.hmac' cannot be read with this instance encryption key

n8n started with a new key against an existing database, for example after .n8n/config was lost. Put the backed-up config back, or set N8N_ENCRYPTION_KEY to the old key.

A workflow needs Execute Command

Remove only that entry: NODES_EXCLUDE=["n8n-nodes-base.localFileTrigger"]. n8n's documentation warns that the node can introduce significant security risks where users are not trusted.

Sources