How to disable 2 factor authentication on command line? Installed twofactor_email, now Can't login!

I just upgraded to NextCloud 16, on my Ubuntu 18.04 server. I had my calendars, contacts, phone sync, etc. setup and working great, but was having trouble using mail for fetching my email accounts. My gmail account said I didn’t have enough security, I mistakenly being in a hurry thought installing twofactor_email may help, now I’m locked out of my own NextCloudserver at home and have not been able to figure out how to gain access as system administrator in nextcloud. I did figure out how to disable twofactor_email through the command line and restart my machine, however I’m still locked out. Fortunately I have backed up copies of everything, so I can’t lose data, NextCloud also backs everything up before upgrading. So is there any way to gain access or restore NextCloud’s backup that it did automatically before upgrading ?

here is some more info:

jason@MyServer:/var/www/html/nextcloud$ sudo -u www-data php occ app:disable twofactor_email

twofactor_email disabled

couldn’t log in later, then disabled it, now getting the following anytime trying to login -

“Message I get when trying to web login”

Two-factor authentication

Could not load at least one of your enabled two-factor auth methods. Please contact your admin.

“NextCloud Logo Was Here”

Two-factor authentication is enforced but has not been configured on your account. Contact your admin for assistance.

[Cancel log in ]

Other Info:

jason@MyServer:~$ cd /var/www/html/nextcloud

jason@MyServer:/var/www/html/nextcloud$ sudo -u www-data php occ app:disable twofactor_email

[sudo] password for jason:

No such app enabled: twofactor_email

jason@MyServer:/var/www/html/nextcloud$ sudo -u www-data php occ app:list

Enabled:

  • accessibility: 1.2.0

  • activity: 2.9.1

  • admin_audit: 1.6.0

  • announcementcenter: 3.5.1

  • bookmarks: 1.0.8

  • calendar: 1.7.0

  • caniupdate: 0.2.0

  • circles: 0.17.5

  • cloud_federation_api: 0.2.0

  • comments: 1.6.0

  • contacts: 3.1.3

  • dav: 1.9.2

  • deck: 0.6.4

  • federatedfilesharing: 1.6.0

  • federation: 1.6.0

  • files: 1.11.0

  • files_accesscontrol: 1.6.0

  • files_antivirus: 2.1.1

  • files_external: 1.7.0

  • files_pdfviewer: 1.5.0

  • files_retention: 1.5.1

  • files_rightclick: 0.13.0

  • files_sharing: 1.8.0

  • files_texteditor: 2.8.0

  • files_trashbin: 1.6.0

  • files_versions: 1.9.0

  • files_videoplayer: 1.5.0

  • firstrunwizard: 2.5.0

  • gallery: 18.3.0

  • groupfolders: 4.0.4

  • logreader: 2.1.0

  • lookup_server_connector: 1.4.0

  • mail: 0.15.1

  • nextcloud_announcements: 1.5.0

  • notes: 3.0.1

  • notifications: 2.4.1

  • oauth2: 1.4.2

  • ocsms: 2.1.3

  • onlyoffice: 2.4.0

  • ownbackup: 19.5.0

  • password_policy: 1.6.0

  • privacy: 1.0.0

  • provisioning_api: 1.6.0

  • quota_warning: 1.5.0

  • ransomware_protection: 1.4.0

  • recommendations: 0.4.0

  • richdocuments: 3.3.14

  • serverinfo: 1.6.0

  • sharebymail: 1.6.0

  • spreed: 6.0.3

  • support: 1.0.0

  • survey_client: 1.4.0

  • systemtags: 1.6.0

  • tasks: 0.11.0

  • theming: 1.7.0

  • twofactor_backupcodes: 1.5.0

  • unsplash: 1.1.3

  • updatenotification: 1.6.0

  • user_usage_report: 1.1.2

  • viewer: 1.0.0

  • weather: 1.6.1

  • workflowengine: 1.6.0

Disabled:

  • encryption

  • ojsxc

  • twofactor_email

  • user_ldap

jason@MyServer:/var/www/html/nextcloud$ sudo -u www-data php occ app:disable twofactor_backupcodes

twofactor_backupcodes can’t be disabled.

jason@MyServer:/var/www/html/nextcloud$

Trying Grep:

jason@MyServer:~$ cd /var/www/html/nextcloud

jason@MyServer:/var/www/html/nextcloud$ sudo -u www-data php occ app:list | grep twofactor

[sudo] password for jason:

  • twofactor_backupcodes: 1.5.0

  • twofactor_email

jason@MyServer:/var/www/html/nextcloud$

I’m guessing there is a way to disable 2 factor authentication, or am I going to have to reinstall again ?

Yes, you can disable it if you have shell access.

https://docs.nextcloud.com/server/16/admin_manual/configuration_server/occ_command.html?highlight=occ#two-factor-auth-label

And a BIG sincere “THANK YOU” to KarlF12

I love the “Life Saving” app Two-Factor Admin Support, however they don’t exactly have the right commands.

To help anyone else using Ubuntu 18.04: The following command does not work
./occ twofactorauth:admin:generate-code leonida

on Ubuntu 18.04: This is what works:
Worked from command line to install:
sudo -u www-data php occ app:install twofactor_admin

Worked to get me the codes to unlock everybody “one at a time”:
sudo -u www-data php occ twofactorauth:admin:generate-code username

Yeeeeeaaaaah I’m Back in,

Thanks to KarlF12

Just a little help, for anyone who installed this in Ubuntu 20.4 using Canonical’s app, you can use this command:

sudo nextcloud.occ twofactorauth:enforce --off --group admin