部署与运维
Use the command line
The Server CLI is a built-in command-line interface that runs on the same machine as your n8n installation. It provides direct database access for administrative tasks and can execute most commands even when n8n isn't running.
When to use Server CLI vs n8n CLI
| Feature | Server CLI | n8n CLI |
|---|---|---|
| Where it runs | Same machine as n8n | Any machine with network access |
| Authentication | Direct database access | API key |
| Requires running n8n | No (most commands) | Yes |
| Best for | Instance operators, backups, migrations | Programmers, AI agents, remote management |
| Security model | Bypasses access controls | Respects user permissions and API key scope |
| Use case examples | Backup/restore, license management, emergency password resets | Workflow automation, credentials management through code |
Running CLI commands
You can use CLI commands with self-hosted n8n. Depending on how you choose to install n8n, there are differences in how to run the commands:
- npm: the
n8ncommand is directly available. The documentation uses this in the examples below. - Docker: the
n8ncommand is available within your Docker container:
docker exec -u node -it <n8n-container-name> <n8n-cli-command>Start a workflow
You can start workflows directly using the CLI.
Execute a saved workflow by its ID:
n8n execute --id <ID>Publish or unpublish a workflow
You can publish or unpublish a workflow using the CLI. In n8n 2.0, the previous active/inactive toggle was replaced by a publish/unpublish model. Use publish:workflow and unpublish:workflow to change a workflow's published state from the CLI.
Publish a workflow
Use publish:workflow to publish a workflow by its ID. You can optionally publish a specific historical version by passing its versionId.
Command flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --id | The ID of the workflow to publish. Required. |
| --versionId | Optional version ID to publish. If omitted, the current draft is published. |
Publish the current draft of a workflow by ID:
n8n publish:workflow --id=<ID>Publish a specific historical version of a workflow:
n8n publish:workflow --id=<ID> --versionId=<VERSION_ID>Unpublish a workflow
Use unpublish:workflow to unpublish a workflow by its ID, or all workflows at once.
Command flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --id | The ID of the workflow to unpublish. Can't be used with --all. |
| --all | Unpublish all workflows. Can't be used with --id. |
Unpublish a workflow by its ID:
n8n unpublish:workflow --id=<ID>Unpublish all workflows:
n8n unpublish:workflow --allupdate:workflow (deprecated)
Set the active status of a workflow by its ID to false:
n8n update:workflow --id=<ID> --active=falseSet the active status of a workflow by its ID to true:
n8n update:workflow --id=<ID> --active=trueSet the active status to false for all the workflows:
n8n update:workflow --all --active=falseSet the active status to true for all the workflows:
n8n update:workflow --all --active=trueExport entities
You can export your database entities from n8n using the CLI. This tooling allows you to export all entity types from one database type, such as SQLite, and import them into another database type, such as Postgres.
Command flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --outputDir | Output directory path |
| --includeExecutionHistoryDataTables | Include execution history data tables, these are excluded by default as they can be very large |
n8n export:entities --outputDir=./outputs --includeExecutionHistoryDataTables=trueExport workflows and credentials
You can export your workflows and credentials from n8n using the CLI.
Command flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --all | Exports all workflows/credentials. |
| --backup | Sets --all --pretty --separate for backups. You can optionally set --output. |
| --id | The ID of the workflow to export. |
| --output, -o | Outputs file name or directory if using separate files. |
| --pretty | Formats the output in an easier to read fashion. |
| --separate | Exports one file per workflow (useful for versioning). Must set a directory using --output. |
| --decrypted | Exports the credentials in a plain text format. (Credentials only.) |
| --version | The version ID of a specific historical version to export. (Workflows only, can't be used with --all or --published.) |
| --published | Exports the published/active version of the workflow instead of the current draft. When combined with --all, unpublished workflows are skipped. (Workflows only, can't be used with --version.) |
Workflows
Export all your workflows to the standard output (terminal):
n8n export:workflow --allExport a workflow by its ID and specify the output file name:
n8n export:workflow --id=<ID> --output=file.jsonExport all workflows to a specific directory in a single file:
n8n export:workflow --all --output=backups/latest/file.jsonExport all the workflows to a specific directory using the --backup flag (details above):
n8n export:workflow --backup --output=backups/latest/Export a specific workflow version
You can export a specific historical version of a workflow by passing its versionId with --version:
n8n export:workflow --id=<ID> --version=<VERSION_ID> --output=workflow-v1.jsonExport the published version of a workflow
Use --published to export the currently published/active version of a workflow rather than the current draft:
n8n export:workflow --id=<ID> --published --output=published.jsonYou can combine --published with --all to export every workflow's published version. Workflows that don't have a published version are skipped:
n8n export:workflow --all --published --output=workflows.jsonCredentials
Export all your credentials to the standard output (terminal):
n8n export:credentials --allExport credentials by their ID and specify the output file name:
n8n export:credentials --id=<ID> --output=file.jsonExport all credentials to a specific directory in a single file:
n8n export:credentials --all --output=backups/latest/file.jsonExport all the credentials to a specific directory using the --backup flag (details above):
n8n export:credentials --backup --output=backups/latest/Export all the credentials in plain text format. You can use this to migrate from one installation to another that has a different secret key in the configuration file.
n8n export:credentials --all --decrypted --output=backups/decrypted.jsonImport entities
You can import entities from a previous export:entities command using this command, it allows importing of entities into a database type that differs from the exported database type. Current supported database types include: SQLite, Postgres.
The database is expected to be empty prior to import, this can be forced with the --truncateTables parameter.
Command flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --inputDir | Input directory that holds output files for import |
| --truncateTables | Truncate tables before import |
n8n import:entities --inputDir ./outputs --truncateTables trueImport workflows and credentials
You can import your workflows and credentials from n8n using the CLI.
Available flags:
| Flag | Description |
|---|---|
| --help | Help prompt. |
| --input | Input file name or directory if you use --separate. |
| --projectId | Import the workflow or credential to the specified project. Can't be used with --userId. |
| --separate | Imports *.json files from directory provided by --input. |
| --userId | Import the workflow or credential to the specified user. Can't be used with --projectId. |
| --skipMigrationChecks | Skip migration validation checks. |
| --activeState | Controls the active state of imported workflows. Accepts false (default, deactivates all imported workflows) or fromJson (uses the active field from each workflow's JSON; multi-main mode only). |
Workflows
Import workflows from a specific file:
n8n import:workflow --input=file.jsonImport all the workflow files as JSON from the specified directory:
n8n import:workflow --separate --input=backups/latest/By default, import:workflow deactivates every imported workflow. To preserve the active field from each JSON file instead, pass --activeState=fromJson (only supported in multi-main & queue mode):
n8n import:workflow --separate --input=backups/latest/ --activeState=fromJsonCredentials
Import credentials from a specific file:
n8n import:credentials --input=file.jsonImport all the credentials files as JSON from the specified directory:
n8n import:credentials --separate --input=backups/latest/License
Clear
Clear your existing license from n8n's database and reset n8n to default features:
n8n license:clearIf your license includes floating entitlements1, running this command will also attempt to release them back to the pool, making them available for other instances.
Info
Display information about the existing license:
n8n license:infoUser management
You can reset user management using the n8n CLI. This returns user management to its pre-setup state. It removes all user accounts.
Use this if you forget your password, and don't have SMTP set up to do password resets by email.
n8n user-management:resetDisable MFA for a user
If a user loses their recovery codes you can disable MFA for a user with this command. The user will then be able to log back in to set up MFA again.
n8n mfa:disable --email=johndoe@example.comDisable LDAP
You can reset the LDAP settings using the command below.
n8n ldap:resetUninstall community nodes and credentials
You can manage community nodes using the n8n CLI. For now, you can only uninstall community nodes and credentials, which is useful if a community node causes instability.
Command flags:
| Flag | Description |
|---|---|
| --help | Show CLI help. |
| --credential | The credential type. Get this value by visiting the node's .credential.ts file and getting the value of name. |
| --package | Package name of the community node. |
| --uninstall | Uninstalls the node. |
| --userId | The ID of the user who owns the credential. On self-hosted, query the database. On cloud, query the API with your API key. |
Nodes
Uninstall a community node by package name:
n8n community-node --uninstall --package <COMMUNITY_NODE_NAME>For example, to uninstall the Evolution API community node, type:
n8n community-node --uninstall --package n8n-nodes-evolution-apiCredentials
Uninstall a community node credential:
n8n community-node --uninstall --credential <CREDENTIAL_TYPE> --userId <ID>For example, to uninstall the Evolution API community node credential, visit the repository and navigate to the credentials.ts file to find the name:
n8n community-node --uninstall --credential evolutionApi --userId 1234Security audit
You can run a security audit on your n8n instance, to detect common security issues.
n8n auditFootnotes
- Back
In n8n, entitlements grant n8n instances access to plan-restricted features for a specific period of time.
官方原文和授权
本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。