How to Create Admin User via Command Line in Magento 2
Vinh Jacker | 03-17-2025

In this tutorial, we will talk about How to Add Admin User via Command Line in the Command Line Series. As you know, in Magento 2, they add many commands in bin/magento
. This may be difficult to approach, so let me explain in more detail.
Who will need this guide?
While creating admin users manually from the backend is the most basic method. Creating admin user accounts via command lines has some advantages if you are in the following conditions:
- Locked Out of the Admin Panel: If you are unable to access the Magento 2 admin panel due to lost credentials or other technical issues, the command line offers a quick way to regain control by creating a new admin user without needing to log into the interface.
- Facing Performance Issues: If your Magento store is experiencing performance problems or slow loading times that make the admin panel difficult to navigate, using the command line ensures that you can perform essential tasks like user creation without waiting for pages to load.
- Working in a Development Environment: For developers who need to frequently create, test, or delete admin users while working in a development or staging environment, the command line speeds up the process significantly, allowing for faster testing and configuration changes.
- Multiple Admin User Creation: If you need to create several admin accounts, doing this via the GUI can be tedious. The command line allows for scripting, meaning you can automate the creation of multiple users efficiently.
- Remote Management: If you manage a Magento store remotely and only have SSH access to the server (without a graphical interface), the command line is your go-to solution for creating admin users and managing other backend tasks.
- Server or Security-Related Restrictions: Some server environments restrict access to the Magento admin panel. In such cases, the command line allows you to bypass these limitations and manage admin users directly.
If you’re also dealing with locked accounts, you can check out our guide on how to unlock admin users via the command line.
How to Create Admin User via Command Line in Magento 2?
Once you have SSH access to the server, navigate to your Magento root directory and check the command syntax:
php bin/magento admin:user:create --help
Output:
Usage:
admin:user:create [options]
Options:
--admin-user=ADMIN-USER (Required) Admin user
--admin-password=ADMIN-PASSWORD (Required) Admin password
--admin-email=ADMIN-EMAIL (Required) Admin email
--admin-firstname=ADMIN-FIRSTNAME (Required) Admin first name
--admin-lastname=ADMIN-LASTNAME (Required) Admin last name
--magento-init-params=MAGENTO-INIT-PARAMS Add to any command to customize Magento initialization parameters
For example: "MAGE_MODE=developer&MAGE_DIRS[base][path]=/var/www/example.com&MAGE_DIRS[cache][path]=/var/tmp/cache"
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Help:
Creates an administrator
This command allows you to create a new admin user quickly with just a few required details.
For example:
Let’s say you want to create an admin account with the following information:
- User: mageplaza
- Password: WeLoveMagento
- Email: [email protected]
- First Name: Mageplaza
- Last Name: Family
So here is the command line:
php bin/magento admin:user:create --admin-user=mageplaza --admin-password=WeLoveMagento [email protected] --admin-firstname=Mageplaza --admin-lastname=Family
It shows an error: Your password must include both numeric and alphabetic characters.
The password should be more complex.
- Password: WeLoveMagento123
php bin/magento admin:user:create --admin-user=mageplaza --admin-password=WeLoveMagento123 [email protected] --admin-firstname=Mageplaza --admin-lastname=Family
Now, we have successfully created a new admin account. The system returns this message:
Created Magento administrator user named mageplaza
Now, go to the admin login page, and fill in the above information
And you are in now, see this screenshot
Want to explore more about managing the admin permissions? Click on the button below:
Conclusion
Creating an admin user via the Magento 2 command line is a fast and reliable method, especially in critical situations where access to the admin panel is restricted. Whether you’re a developer, administrator, or store owner, knowing how to manage admin accounts through the command line will save you time and keep your operations running smoothly.