How to create or change Magento 2 admin password

Sometimes we forget our admin password for our Magento 2 development instance because we usually deal with multiple development instances. Also in most cases, there is no mail service available in a development environment. Hence we could not raise a “forget password” request either. In this case, we can create another admin user from the Magento 2 CLI and change the target account password. But we can also update or in other words, can change Magento 2 admin password with CLI.

Creating a new admin user account

Let’s see how can we use Magento 2 command line tool for creating a new admin user. This CLI command is an interactive application that asks you several questions regarding your admin account preferences.

The following required interactive questions will be asked while creating the user account in CLI.

  • Admin user: the admin username of your choice (existing/new)
  • Admin password: the preferred password for the account (always considered new)
  • Admin email: the preferred email to link to the account (existing/new)
  • Admin first name: the first name of the admin user account
  • Admin last name: the last name of the admin user

We need to provide a new username and email combination that does not already exist in the admin user table. If we provide any of the two that already exist we will get an error saying the account already exists. Hence to create a new account we must provide a combination that is unique in the table.

bin/magento admin:user:create

The following interactive questions will come up in the CLI.

Admin user: admin_user
Admin password: 
Admin email:
Admin first name: admin_user
Admin last name: admin
Created Magento administrator user named adminuser

It’s that simple and easy!

Let’s say we have the following entries in the table after creating the above admin user.

admin_user table

Now if someday I forget the password for “admin_user” which usually happens in a development environment. So how would I update the password with a new one easily? I can change the admin password with the same command and just provide the same username and email but a new password this time. You will see a confirmation message saying “Created Magento administrator user” but actually it will update the existing user in the table.

Change Magento 2 admin user password

We mostly need to change the existing admin user account password that we forget somehow. And it is so easy with Magento 2 CLI. In fact, we don’t need to create another account to change the existing account password. We just need to provide a combination of username and email that already exists and the account password will be changed. So simple and easy.

Unlock an admin account

You can also immediately remove the temporary lock from an admin user account by using the following CLI command.

/bin/magento admin:user:unlock adminuser

Hope this will help you change your Magento 2 admin user password someday with ease.

1 thought on “How to create or change Magento 2 admin password”

Leave a Comment

Share via
Copy link
Powered by Social Snap