42

Having just installed 2.4.0 from scratch, I ran into an "issue" when logging into Magento Backend for the first time:

enter image description here

Failed to send the message. Please contact the administrator You need to configure Two-Factor Authorization in order to proceed to your store's admin area An E-mail was sent to you with further instructions

This implies, that I won't be able to log into Magento without first setting up SMTP on the server. Is there something I'm overlooking that allows me to set this up via the CLI? Therefore, not requiring SMTP to complete the 2FA login.

Edit 1/2

Having slapped the ability for SMTP onto my test server, I got to see what the email was that it was trying to send:

You are required to configure personal Two-Factor Authorization in order to login to Main Website Store To do that please Click here

Clicking the link displayed the following

enter image description here

So, I'm starting to think that an SMTP enabled server should be considered a "prerequisite" for installing Magento. However, I'd prefer to see if anyone has another solution (that doesn't involve disabling 2fA).

Edit 2/2

I ended up reporting this as an issue with Magento. Having 2FA enabled by default was put in place as a security feature. Therefore, having to disable it to make Magento accessible makes that decision absolutely pointless. And yes, I could install SMTP facilities on my server but that seems overkill to send a single email.

1
  • 6
    Setting up 2FA needs to be part of the 2.4 installation docs.. This is crazy. Sep 1, 2020 at 15:31

10 Answers 10

75

For quick access, I recommend disabling the Magento TwoFactorAuth module.

bin/magento module:disable Magento_TwoFactorAuth
6
  • 1
    I hear what you're saying, but that totally defeats the point of enforcing 2FA on installation.
    – Craig
    Jul 29, 2020 at 11:47
  • In my case, I use sudo before the command and working for me. sudo php bin/magento module:disable Magento_TwoFactorAuth Sep 7, 2020 at 12:03
  • I tried to run this command and it says: -bash: bin/magento: Permission denied Why would that be and what do I need to do to make it work?
    – Allysin
    Jan 11, 2021 at 23:27
  • I tried to disable this module but still not working
    – huykon225
    May 21, 2021 at 9:35
  • 3
    Installing Magento locally or in dev server, two factor auth is useless imo Jun 16, 2021 at 14:38
12

please follow the below steps :

1.Select Google Authenticator as the 2FA provider:

php bin/magento config:set twofactorauth/general/force_providers google

2.Increase the lifetime of the window to 60 seconds to prevent tokens from expiring

php bin/magento config:set twofactorauth/google/otp_window 60

3.Use the following key to add the encoded value to the MFTF .credentials file:

magento/tfa/OTP_SHARED_SECRET=Google_Your_secret_key
  1. Add the encoded shared secret to Google Authenticator
php bin/magento security:tfa:google:set-secret admin Google_Your_secret_key

please check this link for more references.enter image description here

Admin => https://i.imgur.com/tOV6fWo.png

Thank You.

2
  • 1
    I read this, but there is a lack of elaboration of Step 3. ("encoded value to the MFTF .credentials file"). i.e. guidelines to generating the Secret Key and the location of the .credentials file.
    – Craig
    Jul 29, 2020 at 8:44
  • Credentials: devdocs.magento.com/mftf/docs/credentials.html
    – Chris
    Aug 27, 2020 at 11:01
5

Buddy I also face the same issue after open admin webpage. You can try to disable 2 Factor Authentication module for first time login using below code in Magento root directory.

bin/magento module:disable Magento_TwoFactorAuth

I know it's not a foolproof step but you can try to login into admin page.

2
  • 1
    Working around the problem isn't an issue. It's just the logic of requiring more prerequisites to support an oversight.
    – Craig
    Aug 5, 2020 at 14:09
  • I tried to run this command and it says: -bash: bin/magento: Permission denied
    – Allysin
    Jan 11, 2021 at 23:24
3

I found a way, by adding a system configuration to Enable/Disable it. I made a module, you can download it with composer:

composer require wolfsellers/module-enabledisabletfa

Or check it at: https://github.com/wolfsellers/module-enabledisabletfa

2

To disable Two Factor Authentication on localhost/dev server.

Execute the php bin/magento module:disable Magento_TwoFactorAuth command.

or,

Open app/etc/config.php and change value for 'Magento_TwoFactorAuth' to 0.

Now execute php bin/magento setup:di:compile command to compile your project.

N:B: You may need to prefix sudo with above commands depending the files and folder permission in your system.

1

Just use this:

$ bin/magento module:disable Magento_TwoFactorAuth

And

$ php bin/magento c:c

1

I had the same issue and was able to resolve the issue by combining the solutions above also solved the permissions denied issue.

  1. php bin/magento config:set twofactorauth/general/force_providers google
  2. php bin/magento config:set twofactorauth/google/otp_window 60
  3. sudo php bin/magento module:disable Magento_TwoFactorAuth

This is what the end result is:

The following modules have been disabled:

  • Magento_TwoFactorAuth

Cache cleared successfully. Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes. Info: Some modules might require static view files to be cleared. To do this, run 'module:disable' with the --clear-static-content option to clear them.

0

You can use the following module to enable/disable Two Factor Authentication on local, dev, or staging environments as you please using admin configuration.

https://github.com/markshust/magento2-module-disabletwofactorauth

0

Hi use this chrome authenticator extension -

https://chrome.google.com/webstore/detail/authenticator/bhghoamapcdpbohphigoooaddinpkbai?hl=en

Scan the QR code with this extension it will decode the code & provide you six digit 2 factor authentication code use this code & it will re-direct you to admin dashboard.

0

Here is a full answer with some additional details based on Nikunj Rawat answer. Sorry if this is wrong but if you know what you're doing there is no excuse for not giving full and complete answers.

Disabling doesn't help because as soon as your turn it on your stuck in the same position and unless you have SMTP setup this solution is the only sensible one that works. Tested in Magento 2.4.4 (May 18th 2022)

please follow the below steps :

1.Select Google Authenticator as the 2FA provider:

php bin/magento config:set twofactorauth/general/force_providers google

2.Increase the lifetime of the window to 60 seconds to prevent tokens from expiring

php bin/magento config:set twofactorauth/google/otp_window 60

3.Create a key (mine is URB4NW4RF4R3 for this example). Use that key in a tool like this to generated your base32 encoded shared secret:

URB4NW4RF4R3 // your shared secret

Screenshot of converting a shared secret into a base32 encoded string

This your secret key you can now enter this into a file called .credentials located in your /magento_document_root/dev/tests/acceptance/

magento/tfa/OTP_SHARED_SECRET=KVJEENCOK42FERRUKIZQ====
  1. Add the encoded shared secret to Google Authenticator. Open the App > click Add and select > Enter a setup key. Give an account name (domain and user) and then enter your Base32 encoded secret into the key field.

  2. Set the secret key against your user account.

php bin/magento security:tfa:google:set-secret admin KVJEENCOK42FERRUKIZQ====
  1. You should now be presented with this screen once you login to your account.

enter image description here

Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.