> 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/basic-configuration/use-environment-variables/user-management-and-2fa.md).

# User management and 2FA

{% hint style="info" %}
**File-based configuration**

You can add `_FILE` to individual variables to provide their configuration in a separate file. Refer to [Keeping sensitive data in separate files](/deploy/host-n8n/configure-n8n/basic-configuration.md#keeping-sensitive-data-in-separate-files) for more details.
{% endhint %}

Refer to [User management](/deploy/host-n8n/configure-n8n/user-management.md) for more information on setting up user management and emails.

| Variable                                        | Type    | Default | Description                                                                                                                                                                                                                                                          |
| ----------------------------------------------- | ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_EMAIL_MODE`                                | String  | `smtp`  | Enable emails.                                                                                                                                                                                                                                                       |
| `N8N_SMTP_HOST`                                 | String  | -       | *your\_SMTP\_server\_name*                                                                                                                                                                                                                                           |
| `N8N_SMTP_PORT`                                 | Number  | -       | *your\_SMTP\_server\_port*                                                                                                                                                                                                                                           |
| `N8N_SMTP_USER`                                 | String  | -       | *your\_SMTP\_username*                                                                                                                                                                                                                                               |
| `N8N_SMTP_PASS`                                 | String  | -       | *your\_SMTP\_password*                                                                                                                                                                                                                                               |
| `N8N_SMTP_OAUTH_SERVICE_CLIENT`                 | String  | -       | If using 2LO with a service account this is your client ID                                                                                                                                                                                                           |
| `N8N_SMTP_OAUTH_PRIVATE_KEY`                    | String  | -       | If using 2LO with a service account this is your private key                                                                                                                                                                                                         |
| `N8N_SMTP_SENDER`                               | String  | -       | Sender email address. You can optionally include the sender name. Example with name: *n8n `<contact@n8n.com>`*                                                                                                                                                       |
| `N8N_SMTP_SSL`                                  | Boolean | `true`  | Whether to use SSL for SMTP (true) or not (false).                                                                                                                                                                                                                   |
| `N8N_SMTP_STARTTLS`                             | Boolean | `true`  | Whether to use STARTTLS for SMTP (true) or not (false).                                                                                                                                                                                                              |
| `N8N_UM_EMAIL_TEMPLATES_INVITE`                 | String  | -       | Full path to your HTML email template. This overrides the default template for invite emails.                                                                                                                                                                        |
| `N8N_UM_EMAIL_TEMPLATES_PWRESET`                | String  | -       | Full path to your HTML email template. This overrides the default template for password reset emails.                                                                                                                                                                |
| `N8N_UM_EMAIL_TEMPLATES_WORKFLOW_SHARED`        | String  | -       | Overrides the default HTML template for notifying users that a workflow was shared. Provide the full path to the template.                                                                                                                                           |
| `N8N_UM_EMAIL_TEMPLATES_CREDENTIALS_SHARED`     | String  | -       | Overrides the default HTML template for notifying users that a credential was shared. Provide the full path to the template.                                                                                                                                         |
| `N8N_UM_EMAIL_TEMPLATES_PROJECT_SHARED`         | String  | -       | Overrides the default HTML template for notifying users that a project was shared. Provide the full path to the template.                                                                                                                                            |
| `N8N_USER_MANAGEMENT_JWT_SECRET`                | String  | -       | Set a specific JWT secret. By default, n8n generates one on start.                                                                                                                                                                                                   |
| `N8N_USER_MANAGEMENT_JWT_DURATION_HOURS`        | Number  | 168     | Set an expiration date for the JWTs in hours.                                                                                                                                                                                                                        |
| `N8N_USER_MANAGEMENT_JWT_REFRESH_TIMEOUT_HOURS` | Number  | 0       | How many hours before the JWT expires to automatically refresh it. 0 means 25% of `N8N_USER_MANAGEMENT_JWT_DURATION_HOURS`. -1 means it will never refresh, which forces users to log in again after the period defined in `N8N_USER_MANAGEMENT_JWT_DURATION_HOURS`. |
| `N8N_MFA_ENABLED`                               | Boolean | `true`  | Whether to enable two-factor authentication (true) or disable (false). n8n ignores this if existing users have 2FA enabled.                                                                                                                                          |
| `N8N_INVITE_LINKS_EMAIL_ONLY`                   | Boolean | `false` | When set to true, n8n will only deliver invite links via email and will not expose them through the API. This option enhances security by preventing invite URLs from being accessible programmatically, or to high privileged users.                                |

## Instance owner using environment variables <a href="#instance-owner-using-environment-variables" id="instance-owner-using-environment-variables"></a>

Set `N8N_INSTANCE_OWNER_MANAGED_BY_ENV` to `true` to pre-provision the instance owner from environment variables. See [Manage instance settings using environment variables](/deploy/host-n8n/configure-n8n/manage-settings-using-environment-variables.md) for how the activation pattern works.

| Variable                            | Type    | Default | Description                                                                                                                                                                                                       |
| ----------------------------------- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `N8N_INSTANCE_OWNER_MANAGED_BY_ENV` | Boolean | `false` | Set to `true` to manage the instance owner from environment variables. When `true`, n8n overwrites the instance owner details below on every startup, locks the UI control for that user, and rejects API writes. |
| `N8N_INSTANCE_OWNER_EMAIL`          | String  | -       | Email address for the instance owner.                                                                                                                                                                             |
| `N8N_INSTANCE_OWNER_FIRST_NAME`     | String  | -       | First name for the instance owner.                                                                                                                                                                                |
| `N8N_INSTANCE_OWNER_LAST_NAME`      | String  | -       | Last name for the instance owner.                                                                                                                                                                                 |
| `N8N_INSTANCE_OWNER_PASSWORD_HASH`  | String  | -       | Bcrypt hash of the instance owner's password. Setting a plaintext password breaks login.                                                                                                                          |

{% hint style="warning" %}
**Owner email must be unique**

`N8N_INSTANCE_OWNER_EMAIL` must not already belong to another user on the instance. This setting updates the existing instance owner account; it doesn't transfer ownership to another existing user or merge user accounts. To use an email address that already belongs to another user, change or delete that user first so the email becomes available.
{% endhint %}


---

# 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/basic-configuration/use-environment-variables/user-management-and-2fa.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.
