Two-factor authentication

Two-factor authentication adds an additional layer of security to user accounts. In order to log in on an account when two-factor authentication (2FA) is enabled, you must provide both the login password and another factor.

To use 2FA two things must happen:

Both steps are described below.

Enabling two-factor authentication

2FA in Nextcloud is pluggable, meaning that various 2FA providers can be used to support different types of factors. Three providers are automatically installed (but may need to be enabled):

Two-Factor TOTP Provider

Two-Factor Authentication via Nextcloud notifications

Two-Factor Backup Codes

Other 2FA providers may be found in the App Store.

../images/2fa-app-install.png

Developers can also implement new two-factor provider apps.

Enforcing two-factor authentication

By default 2FA is optional, hence users are given the choice whether to enable it for their account under their personal settings. Admins may, however, enforce the use of 2FA.

Enforcement is possible system-wide (all users) or for selected groups only. Select groups can also be excluded from 2FA requirements.

These settings can be found under Administration Settings->Security.

../images/2fa-admin-settings.png

When groups are selected/excluded, they use the following logic to determine if a user has 2FA enforced:

Provider removal

Nextcloud keeps records about the enabled two-factor authentication providers of every user. If a provider is simply removed/:ref:`disabled <apps_commands_label>`, Nextcloud will still consider the provider active for the user at login and show a warning like Could not load at least one of your enabled two-factor auth methods.

The associations of removed providers can be cleaned up via :ref:`occ <occ>`:

sudo -E -u www-data php occ twofactorauth:cleanup <provider_id>

Disabling two-factor authentication

Two-factor providers can be disabled via :ref:`occ <occ>`:

sudo -E -u www-data php occ twofactorauth:disable <uid> <provider_id>

This can be useful if the user forgot or lost their second factor. Afterwards users are free to enable this provider again via their personal settings.

It is also possible to check the current two-factor user status via :ref:`occ <occ>`:

sudo -E -u www-data php occ twofactorauth:state <uid>