Enable Two-Factor Authentication in Nextcloud
In this article
Two-factor authentication (2FA) adds a critical second layer of security to your Nextcloud account. Instead of relying only on your password, you’ll also need a one-time code generated on your phone or another device. This guide walks you through enabling 2FA in Nextcloud, both from the user settings and as an administrator enforcing it for your whole instance.
What You'll Need
- Access to your Nextcloud account with administrative privileges (if you plan to enforce 2FA for others).
- A smartphone or tablet with an authenticator app installed (e.g., Google Authenticator, Authy, or a built-in option like iOS Passwords).
- Your Nextcloud password and the ability to log in during the setup process.
Step-by-Step
- Log in to Nextcloud – Open your Nextcloud web interface and sign in with your username and password.
- Open Personal Settings – Click your avatar or profile icon in the top-right corner, then select Settings from the dropdown menu.
- Navigate to Security – In the left sidebar of the Settings page, click Security. This section shows your current sessions, app passwords, and two-factor authentication options.
- Find the Two-Factor Authentication section – Scroll down until you see a panel labeled Two-Factor Authentication. If the administrator has enabled the feature, you’ll see a list of available providers (e.g., TOTP, WebAuthn, or email).
- Choose a provider – Click the Enable button next to your preferred method. For most users, TOTP (time-based one-time password) is the simplest and most secure option. If you have a hardware security key, you can also choose WebAuthn.
- Scan the QR code – Nextcloud will display a QR code and a secret key. Open your authenticator app, tap the plus icon to add a new account, and scan the QR code. If you can’t scan, manually enter the secret key.
- Enter the verification code – After scanning, the app will show a 6-digit code that refreshes every 30 seconds. Enter that code into the Nextcloud field and click Verify or Confirm.
- Save backup codes – Once verified, Nextcloud will generate a set of one-time backup codes. Download or print these and store them in a safe place. Each code can be used only once, and they are essential if you lose your phone.
- Test the login – Log out of Nextcloud and log back in. You should be prompted for your password and then a code from your authenticator app. Enter the code to complete the login.
- For administrators: enforce 2FA for all users – If you manage a Nextcloud instance, go to Settings → Administration → Security. Under Two-Factor Authentication, check the box that says Enforce two-factor authentication and select the provider(s) you want to allow. Users will be required to set up 2FA on their next login.
Common Mistakes
- Skipping backup codes – Many users forget to save the backup codes. If you lose your phone, you’ll be locked out, and recovery can be difficult.
- Using the same code twice – Authenticator codes are single-use. If you enter a code and it fails, wait for the next one to appear.
- Ignoring time sync – TOTP relies on your device’s clock. If your phone’s time is off by more than a minute, codes will be rejected. Enable automatic time sync on your device.
- Not checking the provider list – If you don’t see the 2FA section, your administrator may not have enabled the feature. Check with them or look for an app like Two-Factor TOTP in the Nextcloud app store.
Tips
- Use a reputable authenticator app that supports encrypted backups, such as Authy, so you can recover your codes if you switch phones.
- Store your backup codes in a password manager or a physical safe, not just on your phone.
- If you have a hardware security key, consider enabling WebAuthn as a second method. It’s more phishing-resistant than TOTP.
- For administrators, enforce 2FA gradually – start with a pilot group before rolling out to everyone to avoid support tickets.
- Regularly review the Devices & sessions section in your security settings to revoke any unknown logins.
Troubleshooting
- I don’t see the Two-Factor Authentication section – This feature must be enabled by the administrator. Contact them or check if the twofactor_totp app is installed and enabled in the Apps menu.
- My code is always rejected – First, check that your phone’s time is set to automatic. Then, try entering the code from the authenticator app within the same 30-second window. If it still fails, remove the account from your app and re-scan the QR code (you’ll need to disable and re-enable 2FA in Nextcloud).
- I lost my phone and don’t have backup codes – Contact your Nextcloud administrator. They can disable 2FA for your account from the user management page, allowing you to log in and set it up again.
- 2FA is enforced but some users can’t log in – Users who haven’t set up 2FA will be prompted to do so on their next login. If they’re stuck, the admin can temporarily disable enforcement or reset the user’s 2FA from the admin panel.
- I’m using the mobile app and it asks for a code – The Nextcloud mobile app supports 2FA. After entering your password, it will ask for the code from your authenticator app. If you use app passwords for external clients, those still work without the 2FA code.
Frequently Asked Questions
Do I need a separate app for each Nextcloud account?
No. A single authenticator app can store multiple accounts. Just scan the QR code for each Nextcloud account, and the app will list them separately.
Can I use email or SMS for 2FA?
Nextcloud doesn’t have built-in SMS or email 2FA by default. You can install third-party apps like Two-Factor Email or Two-Factor SMS from the Nextcloud app store, but TOTP is the most common and recommended method.
What happens if I lose my phone after enabling 2FA?
If you saved your backup codes, you can use one of those to log in. If you didn’t, you’ll need to contact your Nextcloud administrator to disable 2FA for your account. After that, you can set it up again with a new device.
Does 2FA work with the Nextcloud desktop and mobile apps?
Yes. The mobile and desktop apps support 2FA. When you log in, you’ll be prompted for the code. For external clients that don’t support 2FA (like some email clients), you can generate an app-specific password in your security settings.
Can I use a hardware security key like a YubiKey?
Yes, if your Nextcloud administrator has enabled the WebAuthn provider. You can then register your hardware key as a second factor. It’s more secure than TOTP and works with a simple tap.
Is 2FA mandatory for all Nextcloud users?
It depends on the administrator. If they have enforced 2FA, every user must set it up. If not, it’s optional. Check your security settings to see if the option is available.