Create, edit, or unlock an administrator account
First steps
-
Log in to the Magento server as, or switch to, a user with permissions to write to the Magento file system. See switch to the file system owner.
If you use the bash shell, you can use the following syntax to switch to the file system owner and enter the command at the same time:
1
su <file system owner> -s /bin/bash -c <command>
If the file system owner does not allow logins, you can do the following:
1
sudo -u <file system owner> <command>
-
To run Magento commands from any directory, add
<magento_root>/bin
to your systemPATH
.Because shells have differing syntax, consult a reference like unix.stackexchange.com.
Sample bash shell for CentOS:
1
export PATH=$PATH:/var/www/html/magento2/bin
Optionally, you can run the commands in the following ways:
cd <magento_root>/bin
and run them as./magento <command name>
<magento_root>/bin/magento <command name>
<magento_root>
is a subdirectory of your web server docroot.
In addition to the command arguments discussed here, see Common arguments.
Prerequisites
Before you can use this command, you must do all of the following:
- Create the deployment configuration
- Enable at minimum the Magento_Authorization and Magento_User modules
- Create the Magento database schema
The simplest way to create the database is to use the command magento setup:upgrade
.
Create or edit an administrator
Use this command to create a new administrator or to edit an existing administrator.
If you’re editing an administrator, only the first name
, last name
, and password
can be edited.
Command usage:
1
bin/magento admin:user:create [--<parameter_name>=<value>, ...]
Where the following table defines parameters and values:
Name | Value | Required? |
---|---|---|
--admin-firstname |
Magento administrator user’s first name. | Yes |
--admin-lastname |
Magento administrator user’s last name. | Yes |
--admin-email |
Magento administrator user’s e-mail address. | Yes |
--admin-user |
Magento administrator username. | Yes |
--admin-password |
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. We recommend a longer, more complex password. If the password string contains special characters that require literal interpretation (such as backslashes or spaces), enclose the password in single quotations. |
Yes |
--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 |
No |
Example of usage:
1
bin/magento admin:user:create --admin-firstname=John --admin-lastname=Doe --admin-email=j.doe@example.com --admin-user=j.doe --admin-password=A0b9%t3g
1
Created Magento administrator user named j.doe
If you do not specify any of required params Magento will ask about them in the CLI:
1
bin/magento admin:user:create
1
2
3
4
5
Admin user: John
Admin password:
Admin email: j.doe.young@example.com
Admin first name: John
Admin last name: Doe Young
1
Created Magento administrator user named John
The following example updates first name
, last name
, and password
of j.doe
admin user:
1
bin/magento admin:user:create --admin-firstname="John X" --admin-lastname="Doe X" --admin-email=j.doe@example.com --admin-user=j.doe --admin-password=A1234567
1
Created Magento administrator user named j.doe
Unlock an administrator account
Use this command to unlock the account of an administrator that was locked, typically because of multiple incorrect login attempts.
1
bin/magento admin:user:unlock {username}
You must specify the administrator’s username. Example:
1
bin/magento admin:user:unlock admin
1
The user account "admin" has been unlocked
If the account is either not unlocked or if there was a problem, the following message displays:
1
The user account "admin" was not locked or could not be unlocked
Verify the user is an administrator, the user is active, and that the account is currently locked. To view the list of locked users in the Admin, log in as an administrator and click System > Permissions > Locked Users.
If the account doesn’t exist, the following message displays:
1
Couldn't find the user account "bob"