Disable 2FA by OCC command

The more strange is it:

sudo nextcloud.occ twofactorauth:state *******
Two-factor authentication is not enabled for user ********

Disabled providers:

  • backup_codes
  • gateway_signal
  • gateway_sms
  • gateway_telegram

sudo nextcloud.occ twofactorauth:enable ******** backup_codes
The provider does not support this operation.

I have always the same problem, the more strange is the the OCC command who say that my account don’t use the 2FA, … Did you think I have to make a new installation of Nextcloud ?

You could create another admin user from the occ command i hope

I can but I dont understand this synthax:
user:add [–password-from-env] [–display-name [DISPLAY-NAME]] [-g|–group [GROUP]] [–]

I didn’t understand how, but now, when I put my login, i’ve not the 2FA interruptions…
It’s very strange, here is the history of all the command I’ve use in SSH, maybe the good command is here:
! I’ve change my real username by “username”, password by “password” for more security…
Also, thank you to had try to help me :slight_smile:

This one should be the good one :
sudo nextcloud.occ twofactorauth:disable username

Don’t forget to have recovery code near you the next time.

You can both disable 2FA and create new admins from occ.

There is also a 2FA app that may interest you that allows you to generate a single use code from occ to get you logged in, as an alternative to turning 2FA off.

Thank you for your answer, but the problem was more important, i couldn’t enter a generated code, I had only “Cancel 2FA” and after that, I was redirect to the login page…

I had this answer:
sudo nextcloud.occ twofactorauth:disable username

[sudo] password for username:
Not enough arguments (missing: “provider_id”).

twofactorauth:disable [–output [OUTPUT]] [–] <provider_id>

You have to specify which 2FA provider you want to disable for the user. You can find the name by running occ config:list.

1 Like

Thanks you for your answer, i will remember this command the next time I will go connect on my server :slight_smile:

For disabling 2FA by OCC , I did below steps and everything is ok and back to Normal
I use Ubuntu 20.04 LTSC with Nextcloud 22.0
1- first we need to have SSH access logion to Sever
2- find nextcloud configuration file for instance (/var/www/nextcloud/config/config.php)
3- edit config.php and try to find line -
{ ‘twofactor_enforced’ => ‘true’, } change it to { ‘twofactor_enforced’ => ‘false’, }
4- remove below lines from config.php file as well
{ ‘twofactor_enforced_groups’ =>
array (
0 => ‘admin’,
),
‘twofactor_enforced_excluded_groups’ =>
array (
), }
5- save it
6 - it’s Done!
7- reboot the server every thing back to normal stage and 2FA is gone!!

@Davoud

Hello, can you show your new (solution) config.php as a code?

Thank you

nc-kay

please use above instruction

  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
);

This are now the last line in my config.php

Where is my mistake?


{ ‘twofactor_enforced_groups’ =>
array (
0 => ‘admin’,
),
‘twofactor_enforced_excluded_groups’ =>
array (
), }

  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  0 => ‘admin’,
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),);

I will try this.

@Davoud
Thank’s for your help, why you didn’t use code tags?
For noobs it is much better.

Now i get the interowsermessage:

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the webserver log.

If i change back to

  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' =>
  array (
  ),
  'twofactor_enforced_excluded_groups' =>
  array (
  ),
);

I get in the webbrowser

https://i.imgur.com/DeHJsat.jpg

I i use this last line

  'updater.release.channel' => 'stable',
  'twofactor_enforced' => 'false',
  'twofactor_enforced_groups' => 
  array (
  0 => ‘admin’,
  ),
  'twofactor_enforced_excluded_groups' => 
  array (
  ),
);

I get

Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the webserver log.

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.