How To Create Admin User Via Command Line In Magento 2

In this post, I will guide you on How To Create Admin User Via Command Line In Magento 2. Use the bin/magento command to create an admin account.

If you are a Magento 2 admin you probably already know the bin/magento commands. Actually, Magento provides a lot of bin/magento commands to help administrators operate the system more easily. You can learn more with Magento 2 SSH/CLI Commands List.

In that set of commands, there is a command that can help you create an admin account easily. Let’s find out in this post.

Steps To Create Admin User Via Command Line In Magento 2

1.  First, you need to connect to your server via SSH as the root user by command:

ssh root@<your-ip-address> -p <your-port-number>

2. Go to Magento 2 root folder.

3. Run the below command:

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

Or use shortcut command:

php bin/magento a:u:c -h

You can see the output like this:

Description:
  Creates an administrator
 
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

Please pay attention to the required items in options when using the command. You will need to have the full user, password, email, first name, last name fields when running the command.

4. Run the command below to create an admin account:

php bin/magento admin:user:create --admin-user=<your-user> --admin-password=<your-password> --admin-email=<your-email> --admin-firstname=<your-firstname> --admin-lastname=<your-lastname>

For example, I will create an account with the following options:

  • user: magetop
  • password: admin123@
  • email: [email protected]
  • firstname: Admin
  • lastname: Magetop

Substituting in the above command we get the command line:

php bin/magento admin:user:create --admin-user=magetop --admin-password=admin123@ [email protected] --admin-firstname=Admin --admin-lastname=Magetop

When created successfully admin account, it returned output:

Created Magento administrator user named magetop
Create successfully admin account

5. Go to Admin Panel and check your result.

This is the end of the post.

Follow us for the more helpful posts!

We hope this is a useful post for you on How To Get Admin Path Command Line In Magento 2.

Thank you for reading!

4.8 4 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x