In this blog, we will learn about how to create admin user in Magento 2?
Sometimes we need to create new admin users for different members to provide access to our backend.
Now, the question is: how do you create a new admin user in Magento 2?
Well, you have three options:
- Through the Magento Admin Panel
- Using the Command Line
- With a PHP Script
Let’s walk through each method step by step.
Method #1: Creating an Admin User Via Magento Admin Panel
This is the most straightforward way and doesn’t require coding knowledge. Perfect if you just want to quickly add a new user.
Step 1: (Optional) Create a User Role
If you want your new admin to have custom permissions (for example, only sales-related access), you can create a new role:
- Go to System → Permissions → User Roles → Add New Role
- Fill in the role details such as Role Name and verify with your current admin password
- In Role Resources, choose “Custom” (for specific access) or “All” (for full access)
- Save the role. For example, you might create a Sales Role.
Step 2: Add a New User
- Navigate to System → Permissions → All Users → Add New User
- Fill out the account details (username, email, password, first name, last name, etc.)
- Confirm with your current admin password
Step 3: Assign a Role
- Choose the role you just created (or the default Admin role)
- Save the user
And that’s it, your new Magento admin user is ready to log in.
Method #2: Creating Admin User in Magento 2 via Command Line
Another way to create an admin user in Magento 2 is by using the command line. If you’re comfortable with the terminal, this method is quick and efficient.
- Open your terminal and navigate to your Magento root directory
- Run the following command:
bin/magento admin:user:create
- After you run the above command Magento will ask for details like username, password, email, first name, and last name.
Once completed, you’ll see a success message like:
Created Magento administrator user named Mageants
This method is handy for developers or when you need to create users during deployment.
Method #3: Creating an Admin User with a PHP Script
For situations where you want to automate user creation or add it to your setup scripts, you can use PHP.
Here’s how:
- Inside your Magento root directory, create a file called adminuser.php
- Add the following code:
<?php use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); try { $adminData = [ 'username' => 'mageants123', 'firstname' => 'admin', 'lastname' => 'admin123', 'email' => 'mageants123@mageants.com', 'password' =>'mageants123', 'interface_locale' => 'en_US', 'is_active' => 1 ]; $userFactory = $objectManager->get('\Magento\User\Model\UserFactory'); $userModel = $userFactory->create(); $userModel ->setData($adminData) ->setRoleId(1) // 1 is administrator unless something has been customized ->save(); } catch (\Exception $exception) { echo $exception->getMessage(); exit; } printf("User %s created", $adminData['username']); - Run the script in terminal:
php adminuser.php
This will instantly create a new admin user with the credentials defined in your script.
Here we use the username ‘mageants123’ and its password is ‘mageants123’.
Conclusion: Magento 2 Create Admin User Programmatically
Using the above article you can easily understand how to create an admin user in Magento 2 programmatically with admin panel, command line and PHP script.
No matter which method you choose, you can easily manage backend access for your team in a secure way.
If you run into any issues while setting this up, our Magento experts are always here to help.
Pro Tip: Along with creating new users, it’s equally important to stay updated on what’s happening inside your store. That’s where our Admin Email Notification for Magento 2 extension comes in.
It automatically notifies you about key backend activities (like order updates, customer actions, or system changes), so you never miss important events.
You might also like our step-by-step guide on How To Send Email to Admin After Customer Registration in Magento 2.
This way, you’ll not only know how to create new admin users but also stay on top of critical updates happening in your store.