In this article we will learn about how we can create admin user inside Magento 2 via a command line. In the event of forgetting your admin password without a configured forget-password email setup, a swift remedy emerges. Create a temporary admin user, providing a convenient and efficient means to regain access and resume seamless management of your Magento platform.
Magento 2, a robust and feature-rich e-commerce platform, allows administrators to manage their online stores efficiently. One crucial aspect is the creation of admin users to ensure secure and controlled access to the backend. Here’s a step-by-step guide on creating an admin user using the command line in Magento 2.
Table of Contents
Access the Command Line
The first step is to Open your terminal or command prompt and navigate to the root directory of your Magento 2 installation. The terminal could be on your local or on the live server where the Magento project resides.
Run the Command
The next step is to execute the following command to create a new admin user.
php bin/magento admin:user:create --admin-user=[username] --admin-password=[password] --admin-email=[email] --admin-firstname=[firstname] --admin-lastname=[lastname]
Replace the placeholders ([username]
, [password]
, [email]
, [firstname]
, and [lastname]
) with the desired values for your new admin user.
--admin-user
: The username for the admin user.--admin-password
: The password for the admin user.--admin-email
: The email address associated with the admin user.--admin-firstname
: The first name of the admin user.--admin-lastname
: The last name of the admin user.
After executing the command you will notice a green color line saying Created Magento administrator user named learningmagento.
Example to create admin user
php bin/magento admin:user:create --admin-user=learningmagento --admin-password=LearningMagento123 --admin-email=contactus@learningmagento.com --admin-firstname=Learn --admin-lastname=Magento
Verify the Creation
Once you’ve executed the command, Magento will create the new admin user. To verify the creation, log in to your Magento backend using the newly created credentials. If you successfully logged in then the process of creation of a new admin was successful.
Two-Factor Authentication in Magento 2
Enhancing the security of your Magento platform is pivotal, and if Two-Factor Authentication (2FA) is enabled, a simple yet crucial step awaits you. Scan the provided barcode using your mobile device to generate a unique 2FA code. This one-time process fortifies your login. For subsequent logins, effortlessly retrieve the code from your mobile device, ensuring a seamless and secure authentication experience.
Important Notes
- Make sure to choose a strong password for security reasons.
- The email address provided should be unique and valid. This is due to an email will be send to the user. In case of Two Factor Auth this part is important.
- After creating the admin user, promptly secure the command history to avoid unintentional exposure of sensitive information.
Custom command
We can create our own custom command and user it accordingly. Like we can create multiple user same time. To know how we can create our own command check our article on Easy way to Create Custom command in Magento.
Overall
Creating an admin user via the command line is a quick and efficient method, particularly useful during initial setup or when managing multiple Magento instances. It ensures that your online store’s backend is accessible only to authorized personnel, enhancing overall security and control. The process to create admin user is same on Adobe commerce.