Disable 2FA by OCC command

ok I see a good solution for disabling 2FA for specific user
step1:
login to server

step2 :,
@ select your nextcloud database , @

mysql
use nextcloud ;
select * from oc_twofactor_providers;

@ you can see the list of all users with their UID , Provider_id
the use below command

#sudo -u www-data php /var/www/nextcloud/occ twofactorauth:disable youruser totp

@youruser === you preferred user in the list @

Regards

1 Like

An easier way is to modify the config.php system setting

“occ config:system:set twofactor_enforced false”

this should disable 2FA if the twofactor_auth:disable command doesn’t work or doesn’t change the config.php file, just use the command below to get back into your system.

occ config:system:set twofactor_enforced false

if you are running nextcloud in a docker container, you can access the container from a terminal window OUTSIDE the container with the following

  1. get <container_id> with → docker container ls

  2. sudo docker exec --user www-data <container_id> php occ config:system:set twofactor_enforced false

You can use occ commands:
How to find out, which provider the User use
For Native System:
sudo -u www-data php /var/www/html/occ twofactor:state $username
For Docker:
docker exec -u www-data nextcloud-aio-nextcloud php /var/www/html/occ twofactor:state $username

For example you get “totp” the Provider is “totp”

OCC Command to disable 2fa for a User
Native System
sudo -u www-data php /var/www/html/occ twofactor:disable $username $provider_id
Docker
docker exec -u www-data nextcloud-aio-nextcloud php /var/www/html/occ twofactor:disable $username $provider_id

You need to change the path of your installation, if your location is another.
If you not use Nextcloud AIO you need to change the Container Name of the Nextcloud Container.

Admin i wouldnt enforce 2FA, cause you can have problems in some cases.