Reset a Lost Nextcloud Admin Password with OCC

Being locked out of Nextcloud’s web interface does not prevent a server administrator from changing a local account password. If you can access the server shell, run Nextcloud’s built-in occ user:resetpassword command as the web-server user, then sign in with the same account name and the new password. The command works for administrator accounts as well as regular users; “admin” is only an example username.

The commands below follow the Nextcloud 35 Administration Manual, checked October 10, 2026. Replace the example installation path, HTTP user, PHP executable, and username with the values used by your server.

Reset the password interactively

1. Find the Nextcloud installation and web-server account

Connect to the host with an account that can use a shell and elevate privileges. Locate the directory containing the occ script. A common Ubuntu or Debian path is /var/www/nextcloud; some packaged, container, or hosted installations use another location. The command must run in the Nextcloud installation context and as the HTTP user so file ownership remains consistent.

On Debian or Ubuntu, that user is commonly www-data. Nextcloud documents apache for Fedora or CentOS, http for Arch, and wwwrun for openSUSE. Use your actual web-server account, not necessarily the Linux account you use to log in.

2. Run the OCC password reset command

Use this command on a typical Debian or Ubuntu installation, substituting the correct username if it is not admin:

sudo -u www-data php /var/www/nextcloud/occ user:resetpassword admin

Nextcloud prompts for a new password and asks you to enter it again. The password is not placed in the shell command, which avoids leaving it in shell history. When the command reports that it successfully reset the password, try the web login with that username and the new password. Do not include angle brackets around the username when substituting it.

The official documentation also shows sudo -E -u www-data. The -E option preserves environment variables; it is not needed for the usual interactive reset unless your installation requires particular environment settings. Run occ with the PHP CLI version configured for your web server. If the default php executable is incompatible, call the matching PHP binary explicitly.

If you are not sure which account to reset

The login name is the account’s Nextcloud username, not necessarily its display name or email address. If you have another administrator account, use the Users page to confirm the affected login name. From the command line, an administrator can list accounts with:

sudo -u www-data php /var/www/nextcloud/occ user:list

Replace www-data and the OCC path as needed. The output may include many user accounts, so avoid sharing it publicly if it contains identifying information. For very large installations, the command supports options such as limits and offsets; check the current occ help user:list output for the syntax available in your version.

If you still have access to another Nextcloud administrator, asking them to reset your password in the Users settings is a simpler option. The login-page reset link is another option only if a valid email address was previously saved on your Personal page and the server can send mail. OCC is useful when neither route is available but shell access is.

Handle common command-line problems

“Could not open input file” or “occ not found”

The command is pointing to the wrong installation directory. Change the path to the actual occ script. You can also change into the installation directory and run the shorter form sudo -u www-data php occ user:resetpassword admin. Do not run a similarly named script from a different Nextcloud copy on the same server.

Permission, cache, or PHP errors

Confirm that you used the HTTP account and the same PHP CLI version expected by the installation. Nextcloud’s OCC documentation notes that APCu is disabled by default in PHP command-line mode; if OCC reports that APCu is unavailable, enable apc.enable_cli for the correct CLI configuration or follow the documented --define apc.enable_cli=1 invocation. Do not change web PHP settings blindly just to address a CLI-specific error.

The account uses an external identity provider

Some installations authenticate accounts through LDAP, SAML, or another external identity provider. In that case, the provider may be the authority for the password, and an OCC reset against Nextcloud’s local account data may not change the credential used at sign-in. Reset the password through the identity provider’s approved process, or verify that the configured backend supports password changes before using OCC. This command is for the Nextcloud account password and does not reset an identity provider’s own credentials.

You run Nextcloud in a container or managed hosting

Run OCC in the application container or through the provider’s supported shell, not on an unrelated host. Container names, installation paths, PHP commands, and service users differ by deployment, so do not copy a Docker command written for another image without checking its documentation. Managed hosting may restrict shell access; use its control panel or request the provider’s documented recovery method if you cannot run OCC.

Verify that you regained access

Check that OCC printed a success message, then open the usual Nextcloud URL in a private browser window and sign in with the exact username and new password. A private window helps distinguish a password issue from an old session or cached login page. Once signed in, confirm that the account still has administrator access and that you can open Administration settings. If login still fails, recheck the username, authentication backend, server log, and whether OCC ran against the correct instance; repeating the reset against the wrong copy will not fix the active server.

Official references

Leave a Comment

Reset a Lost Nextcloud Admin Password with OCC

Use Nextcloud’s OCC command to reset an administrator password from the server shell, with guidance for usernames, permissions, and external login providers.

Add the HSTS Header at the HTTPS Endpoint Serving Nextcloud

Clear Nextcloud’s HSTS warning by setting the header at Apache, NGINX, or your TLS proxy, then verify the public HTTPS response safely.

Troubleshoot Nextcloud App Installs That Report No Internet

Troubleshoot Nextcloud App Installs That Report No Internet

Trace App Store installation failures to DNS, HTTPS, proxy, TLS, or configuration issues from the Nextcloud server itself.

Tame Nextcloud Preview CPU Spikes with a Scheduled Queue

Move thumbnail work to a controlled background schedule, trim unused preview sizes, and verify the queue without overwhelming your Nextcloud server.

Get Nextcloud Desktop Sync Moving Past “Processing Files”

Find the file, exclusion rule, connection issue, or client database state holding up Nextcloud sync, then verify uploads and downloads safely.

Clear the Nextcloud OPcache Warning by Adjusting the Right Limit

Find the PHP OPcache limit triggering Nextcloud’s warning, update the correct web PHP configuration, restart safely, and verify the result.

Connect Nextcloud to CODE Docker: Setup and Tradeoffs

Connect Nextcloud to CODE Docker: Setup and Tradeoffs

Compare built-in and Docker-based CODE, then connect Collabora Online to Nextcloud through a secure HTTPS reverse proxy.

Build a Resilient Nextcloud Cluster with Galera

Plan a reliable Nextcloud HA deployment with shared storage, Redis locking, quorum-aware MariaDB routing, and practical failover checks.

Get Nextcloud Talk Calls Through When Direct Media Fails

Get Nextcloud Talk Calls Through When Direct Media Fails

Configure and verify a reachable TURN relay for Nextcloud Talk when firewalls or restrictive NAT block direct call media.

Clear Nextcloud Integrity Warnings by Restoring the Right Files

Use the invalid-file report to identify changed, missing, or extra Nextcloud code, restore trusted files safely, and verify the result.