Locked out of the Magento admin, inherited a store without any admin credentials, or just need to give a new developer access quickly? You don’t have to dig into the database or reinstall anything. Magento 2 ships with a CLI command that creates (or updates) an administrator account in a few seconds.
In this tutorial, we will learn how to create an admin user in Magento 2 via command line with bin/magento admin:user:create, how to use the interactive mode, how to change an existing admin password, and how to unlock an admin account or reset its two-factor authentication. The commands work on Magento Open Source and Adobe Commerce 2.4.x, including 2.4.8.
Previously, I published a tutorial on how to fix “You did not sign in correctly or your account is temporarily disabled” in Magento 2. Creating a fresh admin user from the command line is the fastest way out when none of the existing accounts work.
Contents
- Requirements
- Step 1: Connect to the server and go to the Magento root
- Step 2: Create an admin user in Magento 2 with admin:user:create
- Step 3 (alternative): Use the interactive mode
- Step 4: Log in and set up two-factor authentication
- Step 5: Check the new user in the admin panel
- How to change an admin password from the command line
- How to unlock an admin account and reset 2FA
- Common errors
- Wrapping up
Requirements
- SSH access to the server where Magento is installed.
- A working Magento installation: the deployment configuration (
app/etc/env.php) exists, the database schema is installed, and theMagento_UserandMagento_Authorizationmodules are enabled (they are by default). - You run commands as the Magento file system owner, not as
root. Runningbin/magentoas root creates cache files that the web server can’t write later.
If you are still setting up a new store, see how to install Magento 2.4 on Ubuntu first. The installer already creates the first admin user, and you can use this tutorial to add more.
Step 1: Connect to the server and go to the Magento root
Log in via SSH and switch to the Magento root directory (the folder that contains bin/, app/ and composer.json). The path below is an example, replace it with yours:
ssh magento@your-server-ip cd /var/www/magento2
If you only have root access, switch to the file system owner first, for example sudo -u www-data -s or su magento, depending on your setup.
Step 2: Create an admin user in Magento 2 with admin:user:create
The command syntax is:
bin/magento admin:user:create [--<option>=<value>, ...]
These are the options you need:
--admin-user: the username used to log in to the admin.--admin-password: the password. Adobe’s documentation requires at least 12 characters with both letters and numbers. Wrap it in single quotes if it contains special characters, so your shell doesn’t interpret them.--admin-email: the email address of the administrator. It must be unique among admin users.--admin-firstnameand--admin-lastname: first and last name.--magento-init-params(optional): custom application initialization parameters, only needed on unusual setups.
Here is a complete example:
bin/magento admin:user:create \ --admin-user=john.doe \ --admin-password='Str0ngPass2026' \ --admin-email=john@example.com \ --admin-firstname=John \ --admin-lastname=Doe
If everything is correct, Magento prints a confirmation message:
Created Magento administrator user named john.doe
Please use your own strong password instead of the example above. Also keep in mind that the password stays in your shell history when you pass it as an option. You can avoid that with the interactive mode in the next step.
Step 3 (alternative): Use the interactive mode
If you run the command without options, Magento asks for each required value one by one. The password prompt doesn’t show what you type, and the password doesn’t end up in your bash history:
bin/magento admin:user:create
Step 4: Log in and set up two-factor authentication
Open your admin URL in the browser and log in with the new username and password. If you don’t remember the admin path, run bin/magento info:adminuri to print it, or follow my guide on how to change the default admin URL in Magento 2.
Since Magento 2.4.0, two-factor authentication (2FA) is enabled by default. On the first login, the new admin is asked to configure a 2FA provider such as Google Authenticator. Magento sends the setup link by email, so your store must be able to send emails.
On a local development environment without mail, many developers disable the 2FA modules. Never do this on a production store:
bin/magento module:disable Magento_AdminAdobeImsTwoFactorAuth Magento_TwoFactorAuth bin/magento setup:upgrade bin/magento cache:flush
On older 2.4.x versions where Magento_AdminAdobeImsTwoFactorAuth doesn’t exist, disable only Magento_TwoFactorAuth.
Step 5: Check the new user in the admin panel
Go to System > Permissions > All Users. The new account appears in the grid, and when you open it you can see that it is active and assigned to the Administrators role, which has full access.
If the user should only manage orders or catalog, create a restricted role in System > Permissions > User Roles and change the User Role tab of this account after you create it.
How to change an admin password from the command line
The same command also edits an existing admin. Run it with the existing username and the new values. According to Adobe’s documentation, only the first name, last name and password can be changed this way:
bin/magento admin:user:create \ --admin-user=john.doe \ --admin-password='N3wStrongPass2026' \ --admin-email=john@example.com \ --admin-firstname=John \ --admin-lastname=Doe
Don’t be confused by the output: Magento still prints Created Magento administrator user named john.doe even though it updated the existing account.
How to unlock an admin account and reset 2FA
After too many failed login attempts, Magento locks the account. Unlock it with:
bin/magento admin:user:unlock john.doe
You should see The user account "john.doe" has been unlocked. If you see was not locked or could not be unlocked, the account wasn’t locked in the first place, so check the username and password instead. You can also review locked accounts in System > Permissions > Locked Users.
If the admin lost the phone with the authenticator app, reset their 2FA provider so they can configure it again on the next login (replace google with the provider code the user configured):
bin/magento security:tfa:reset john.doe google bin/magento cache:flush
Related: if your admins get logged out too quickly after signing in, see how to change the admin session timeout in Magento 2.
Common errors
“There are no commands defined in the “admin:user” namespace”
The admin commands are only available on an installed Magento instance. Make sure you are in the correct directory, that app/etc/env.php exists and that the database connection works. If the Magento_User module is disabled, enable it with bin/magento module:enable Magento_User.
“User with the same user name or email already exists.”
Another admin account already uses this email address. Use a different email, or update the existing account instead.
Password rejected
If Magento rejects the password, make it longer and include both letters and numbers. Wrap passwords with special characters such as $ or ! in single quotes, otherwise bash changes them before Magento receives them, and you won’t be able to log in with the password you think you set.
Permission denied or the admin shows errors after running the command
You probably ran bin/magento as root. Fix the ownership of var/, generated/ and pub/static/ so the web server user owns them again, then flush the cache with bin/magento cache:flush.
For the full reference, see Adobe’s official guide: Create, edit, or unlock an administrator account.
Wrapping up
That’s all you need to create an admin user in Magento 2 via command line: SSH into the server, run bin/magento admin:user:create with a strong password (or use the interactive mode), log in and set up 2FA. The same command changes the password of an existing admin, and admin:user:unlock or security:tfa:reset get a locked-out admin back in.
If you get an error that isn’t covered here, leave a comment below with your Magento version and the full error message, and I’ll help you fix it.






