> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/deploy/host-n8n/configure-n8n/use-the-command-line.md).

# 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.

{% hint style="info" %}
**n8n CLI**

Looking to interact with n8n programmatically from a remote machine or integrate with AI agents? Check out the [n8n CLI](https://docs.n8n.io/connect/).
{% endhint %}

## When to use Server CLI vs n8n CLI <a href="#when-to-use-server-cli-vs-n8n-cli" id="when-to-use-server-cli-vs-n8n-cli"></a>

| 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 <a href="#running-cli-commands" id="running-cli-commands"></a>

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 `n8n` command is directly available. The documentation uses this in the examples below.
* Docker: the `n8n` command is available within your Docker container:

  ```sh
  docker exec -u node -it <n8n-container-name> <n8n-cli-command>
  ```

## Start a workflow <a href="#start-a-workflow" id="start-a-workflow"></a>

You can start workflows directly using the CLI.

Execute a saved workflow by its ID:

```bash
n8n execute --id <ID>
```

## Publish or unpublish a workflow <a href="#publish-or-unpublish-a-workflow" id="publish-or-unpublish-a-workflow"></a>

You can publish or unpublish a workflow using the CLI. In n8n 2.0, the [previous active/inactive toggle](/release-notes/v20-breaking-changes.md) was replaced by a publish/unpublish model. Use `publish:workflow` and `unpublish:workflow` to change a workflow's published state from the CLI.

{% hint style="info" %}
**Restart required**

These commands operate on your n8n database. If you execute them while n8n is running, the changes don't take effect until you restart n8n.
{% endhint %}

### Publish a workflow <a href="#publish-a-workflow" id="publish-a-workflow"></a>

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. |

{% hint style="info" %}
**No `--all` flag**

Unlike the deprecated `update:workflow` command, `publish:workflow` doesn't support `--all`. This is intentional: it prevents accidental bulk publishing of workflows in production environments. Publish workflows individually by ID.
{% endhint %}

Publish the current draft of a workflow by ID:

```bash
n8n publish:workflow --id=<ID>
```

Publish a specific historical version of a workflow:

```bash
n8n publish:workflow --id=<ID> --versionId=<VERSION_ID>
```

### Unpublish a workflow <a href="#unpublish-a-workflow" id="unpublish-a-workflow"></a>

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:

```bash
n8n unpublish:workflow --id=<ID>
```

Unpublish all workflows:

```bash
n8n unpublish:workflow --all
```

### update:workflow (deprecated) <a href="#updateworkflow-deprecated" id="updateworkflow-deprecated"></a>

{% hint style="warning" %}
**Deprecated in n8n 2.0**

The `update:workflow` command is deprecated and will be removed. Use [`publish:workflow`](#publish-a-workflow) and [`unpublish:workflow`](#unpublish-a-workflow) instead. See the [n8n v2.0 breaking changes](/release-notes/v20-breaking-changes.md) for details.
{% endhint %}

Set the active status of a workflow by its ID to false:

```bash
n8n update:workflow --id=<ID> --active=false
```

Set the active status of a workflow by its ID to true:

```bash
n8n update:workflow --id=<ID> --active=true
```

Set the active status to false for all the workflows:

```bash
n8n update:workflow --all --active=false
```

Set the active status to true for all the workflows:

```bash
n8n update:workflow --all --active=true
```

## Export entities <a href="#export-entities" id="export-entities"></a>

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 |

```bash
n8n export:entities --outputDir=./outputs --includeExecutionHistoryDataTables=true
```

## Export workflows and credentials <a href="#export-workflows-and-credentials" id="export-workflows-and-credentials"></a>

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 <a href="#workflows" id="workflows"></a>

Export all your workflows to the standard output (terminal):

```bash
n8n export:workflow --all
```

Export a workflow by its ID and specify the output file name:

```bash
n8n export:workflow --id=<ID> --output=file.json
```

Export all workflows to a specific directory in a single file:

```bash
n8n export:workflow --all --output=backups/latest/file.json
```

Export all the workflows to a specific directory using the `--backup` flag (details above):

```bash
n8n export:workflow --backup --output=backups/latest/
```

#### Export a specific workflow version <a href="#export-a-specific-workflow-version" id="export-a-specific-workflow-version"></a>

You can export a specific historical version of a workflow by passing its `versionId` with `--version`:

```bash
n8n export:workflow --id=<ID> --version=<VERSION_ID> --output=workflow-v1.json
```

#### Export the published version of a workflow <a href="#export-the-published-version-of-a-workflow" id="export-the-published-version-of-a-workflow"></a>

Use `--published` to export the currently published/active version of a workflow rather than the current draft:

```bash
n8n export:workflow --id=<ID> --published --output=published.json
```

You can combine `--published` with `--all` to export every workflow's published version. Workflows that don't have a published version are skipped:

```bash
n8n export:workflow --all --published --output=workflows.json
```

{% hint style="info" %}
**Version metadata**

When exporting a workflow, n8n includes a `versionMetadata` property containing the workflow's historical name and description for that version. The import command preserves this data in the workflow history table on import. The current workflow's name and description aren't overridden.
{% endhint %}

### Credentials <a href="#credentials" id="credentials"></a>

Export all your credentials to the standard output (terminal):

```bash
n8n export:credentials --all
```

Export credentials by their ID and specify the output file name:

```bash
n8n export:credentials --id=<ID> --output=file.json
```

Export all credentials to a specific directory in a single file:

```bash
n8n export:credentials --all --output=backups/latest/file.json
```

Export all the credentials to a specific directory using the `--backup` flag (details above):

```bash
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.

{% hint style="warning" %}
**Sensitive information**

All sensitive information is visible in the files.
{% endhint %}

```bash
n8n export:credentials --all --decrypted --output=backups/decrypted.json
```

## Import entities <a href="#import-entities" id="import-entities"></a>

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                      |

```bash
n8n import:entities --inputDir ./outputs --truncateTables true
```

## Import workflows and credentials <a href="#import-workflows-and-credentials" id="import-workflows-and-credentials"></a>

You can import your workflows and credentials from n8n using the CLI.

{% hint style="warning" %}
**Update the IDs**

When exporting workflows and credentials, n8n also exports their IDs. If you have workflows and credentials with the same IDs in your existing database, they will be overwritten. To avoid this, delete or change the IDs before importing.
{% endhint %}

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). |

{% hint style="info" %}
**Migrating to SQLite**

n8n limits workflow and credential names to 128 characters, but SQLite doesn't enforce size limits.

This might result in errors like **Data too long for column name** during the import process.

In this case, you can edit the names from the n8n interface and export again, or edit the JSON file directly before importing.
{% endhint %}

### Workflows <a href="#workflows" id="workflows"></a>

{% hint style="warning" %}
**Known issue: cron triggers keep running after import**

The behaviour of importing a previously active workflow differs depending on the mode you are running. This is a known bug.

On multi-main and queue-mode instances the previously active workflow's cron triggers are deactivated on import.

On non multi-main instances the previously active workflows cron triggers will remain running until you restart the n8n instance.
{% endhint %}

Import workflows from a specific file:

```bash
n8n import:workflow --input=file.json
```

Import all the workflow files as JSON from the specified directory:

```bash
n8n import:workflow --separate --input=backups/latest/
```

{% hint style="info" %}
**Version metadata on import**

If the imported file includes a `versionMetadata` property (added by exports that target a specific version or the published version), n8n preserves that historical name and description in the workflow history table. The current workflow entity's name and description are kept as-is.
{% endhint %}

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):

```bash
n8n import:workflow --separate --input=backups/latest/ --activeState=fromJson
```

### Credentials <a href="#credentials" id="credentials"></a>

Import credentials from a specific file:

```bash
n8n import:credentials --input=file.json
```

Import all the credentials files as JSON from the specified directory:

```bash
n8n import:credentials --separate --input=backups/latest/
```

## License <a href="#license" id="license"></a>

### Clear <a href="#clear" id="clear"></a>

Clear your existing license from n8n's database and reset n8n to default features:

```sh
n8n license:clear
```

If your license includes [floating entitlements](#user-content-fn-1)[^1], running this command will also attempt to release them back to the pool, making them available for other instances.

### Info <a href="#info" id="info"></a>

Display information about the existing license:

```sh
n8n license:info
```

## User management <a href="#user-management" id="user-management"></a>

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.

```sh
n8n user-management:reset
```

### Disable MFA for a user <a href="#disable-mfa-for-a-user" id="disable-mfa-for-a-user"></a>

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.

```sh
n8n mfa:disable --email=johndoe@example.com
```

### Disable LDAP <a href="#disable-ldap" id="disable-ldap"></a>

You can reset the LDAP settings using the command below.

```sh
n8n ldap:reset
```

## Uninstall community nodes and credentials <a href="#uninstall-community-nodes-and-credentials" id="uninstall-community-nodes-and-credentials"></a>

You can manage [community nodes](/integrations/community-nodes/installation-and-management.md) 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 `<NODE>.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 <a href="#nodes" id="nodes"></a>

Uninstall a community node by package name:

```sh
n8n community-node --uninstall --package <COMMUNITY_NODE_NAME>
```

For example, to uninstall the [Evolution API community node](https://www.npmjs.com/package/n8n-nodes-evolution-api), type:

```sh
n8n community-node --uninstall --package n8n-nodes-evolution-api
```

### Credentials <a href="#credentials" id="credentials"></a>

Uninstall a community node credential:

```sh
n8n community-node --uninstall --credential <CREDENTIAL_TYPE> --userId <ID>
```

For example, to uninstall the [Evolution API community node credential](https://www.npmjs.com/package/n8n-nodes-evolution-api), visit the [repository](https://github.com/oriondesign2015/n8n-nodes-evolution-api) and navigate to the [`credentials.ts` file](https://github.com/oriondesign2015/n8n-nodes-evolution-api/blob/main/credentials/EvolutionApi.credentials.ts) to find the `name`:

```sh
n8n community-node --uninstall --credential evolutionApi --userId 1234
```

## Security audit <a href="#security-audit" id="security-audit"></a>

You can run a [security audit](/deploy/host-n8n/configure-n8n/security/run-security-audits.md) on your n8n instance, to detect common security issues.

```sh
n8n audit
```

[^1]: In n8n, entitlements grant n8n instances access to plan-restricted features for a specific period of time.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/deploy/host-n8n/configure-n8n/use-the-command-line.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
