Create New Admin User in Magento 2 via Command Line Interface

Creating a new admin user via the command line interface is one of the great features in Magento 2. It is very helpful and quick process while we forgot the Magento 2 admin credential.

Create Admin User via Command Line

Here is the CLI command which helps you to create a new admin user in Magento 2, run the following command in the path of your Magento 2 installed root directory,

php bin/magento admin:user:create --admin-user="admin" --admin-password="Admin@123" --admin-email="" --admin-firstname="MyFirstName" --admin-lastname="MyLastName"

The above command will return the following success message after creating an admin user account,

Created Magento administrator user named admin

While we run the above command in the CLI, the following file will be executed in order to create a new admin user,

<Magento 2 Root Directory>/vendor/magento/magento2-base/setup/src/Magento/Setup/Console/Command/AdminUserCreateCommand.php

You may also create a admin users from command line interactively which is included in the latest versions of Magento.

Here is the command to create a new admin user,

php bin/magento admin:user:create

It will prompt you to enter the following required fields one by one.

  • Admin user: Magento administrator user’s first name.
  • Admin password: Magento administrator user’s last name.
  • Admin email: Magento administrator user’s e-mail address.
  • Admin first name: Magento administrator username.
  • Admin last name: Magento administrator user password. The password must be at least 7 characters in length and must include at least one alphabetic and at least one numeric character.

It is quite easy and cool.

Unlock Admin User via Command Line

Sometimes the admin account will lock because of multiple incorrect login attempts. Use the following command to unlock those type of admin user account.

php bin/magento admin:user:unlock {username}


php bin/magento admin:user:unlock admin

The above command will return the following success message,

The user account "admin" has been unlocked

Run the following command in your command line interface to get the list of all the options for creating admin user in Magento 2,

php bin/magento admin:user:create --help

It will return the output as follows,

    Creates an administrator
    admin:user:create [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/[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

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *