Most Magento admin break-ins don’t need any clever hacking. Someone reuses a password that leaked from another site, or a bot guesses a weak one. Two-factor authentication (2FA) stops both, because a password alone is no longer enough to log in.

Is it on?

Magento 2.4 includes 2FA in the Magento_TwoFactorAuth module, and it is on by default. Many stores switch it off during development and never switch it back. Check:

bin/magento module:status Magento_TwoFactorAuth

If it says Module is disabled, your admin is protected by passwords alone.

Turn it on

bin/magento module:enable Magento_TwoFactorAuth
bin/magento setup:upgrade
bin/magento cache:flush

On a production store, also run setup:di:compile and setup:static-content:deploy after setup:upgrade, as for any module change, and do it in a quiet period.

Choose the methods

Under Stores > Configuration > Security > 2FA, pick which methods admins may use:

  • Google Authenticator (works with any authenticator app, such as Google Authenticator, Microsoft Authenticator or 1Password). The simplest choice for most teams.
  • Duo Security, if your company already uses Duo.
  • U2F / WebAuthn security keys, such as YubiKey, for the strongest protection.

The next time each admin logs in, Magento walks them through setting up their method.

Make sure Magento can send email

The first setup link is sent by email. If your store cannot send mail, admins get stuck. Test email delivery before enabling 2FA on a live store.

When someone loses their phone

Reset their 2FA from the command line, and they set it up again at the next login:

bin/magento security:tfa:reset john.smith google

Replace john.smith with the admin username and google with the method they used.

Close the other doors too

  • Move the admin to a custom address (see changing the Magento admin URL).
  • Turn on admin account lockout after failed logins, and reCAPTCHA on the admin login.
  • Give every person their own admin account, and remove accounts for people who have left.

Catch it automatically

MageMonitor checks for this every few minutes as part of its Security Center checks, and alerts you by email, Slack or webhook the moment it appears, with the exact commands to fix it. See MageMonitor for Magento 2.

Related fixes