How to reset user password from command line


PHP 8.1.2-1ubuntu2.17 (cli)
Ubuntu - 22.04

I am having issues to reset user accounts password.
sudo -u www-data php /var/www/nextcloud/occ user:resetpassword admin

I have tried above command as can not find location for /var/www
i had no php so installed above version

need help to reset one user password.

I have 2 user one is logged in on phone app but dont know password so can’t use that to reset password from dashboard

i never setup email to reset password from link…
So only option I suspect is from command line

I have tried below command also but then error for occ folder.

php occ user:resetpassword admin

Could not open input file: occ

could someone please help to rest password.

thanks in advance!


How do you run Nextcloud if no PHP was installed?

It sounds to me you are not on the server Nextcloud is running or you are using Nextcloud with Docker, Snap or something else. If you are using Docker, for example, the way you call the CLI tool is different or you have to go into the container first. An example for Docker is documented here:

docker exec --user www-data CONTAINER_ID php occ

You must pass occ with the complete path as the user that runs Nextcloud, which is www-data on Ubuntu. So if your Nextcloud is installed in /var/www/nextcloud, the occ call must be done like this:

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

This is all described → here ← in the manual.

Much and good luck,

1 Like

Thanks Ernolf for reply.

Even to test I run
sudo -u www-data php occ
Could not open input file: occ

I install Next cloud on Ubuntu 22.04 version
as i mentioned I was not able to Run php commands then i downloaded app. how i can install occ?

i dont have www folder under /var


occ is part of nextcloud server.

Let me repeat the question that @mritzmann asked:


I downloaded Ubuntu 22.04.4 server and install Nextcloud a part of it during initial installation.

so wondering if i had to install PHP do or can I install occ also to execute command to reset password.



OK, then you have Nextcloud as a Snap. That’s a different case. I’m not a Snap specialist.
Maybe someone with Snap experience can answer.

Much and good luck,

1 Like

Hi Mritzmann

as I replied and found out from Ernolf I Nextcloud as snap.

is there way to reset user account password ?


Does this help? :slight_smile:


Thank you so much this worked like charm!


1 Like