If you’re working with Magento 2, there are times when you need to manage admin users directly from the command line — especially if you’re locked out of the admin panel or working on a staging site. Fortunately, Magento 2’s CLI tools make user management fast and efficient.
In this guide, we’ll walk you through how to create, reset, and unlock Magento 2 admin users using CLI commands, so you can get back to work in no time.
⚙️ Prerequisites
Make sure:
- You have SSH access to your Magento 2 server.
- The Magento installation is working and the CLI (
bin/magento) is accessible. - You have sufficient file system permissions to run terminal commands.
👤 1. Create a New Admin User via CLI
Use the following command to create a new admin user
bin/magento admin:user:create
--admin-user='newadmin'
--admin-password='Password123'
--admin-email='admin@example.com'
--admin-firstname='Admin'
--admin-lastname='User'
🔐 Password Tip: Magento requires strong passwords. Use at least one uppercase letter, one lowercase letter, one number, and one special character.
This command creates a brand-new admin account that you can use to log in instantly.
🔁 2. Reset Password for an Existing Admin User
If you forgot the password or need to reset access for another user, you can quickly update the password from the terminal:
bin/magento admin:user:password-reset --admin-user='newadmin'
You’ll be prompted to enter a new password. Once updated, the user can log in immediately.
🔓 3. Unlock a Locked Admin User
Magento automatically locks accounts after too many failed login attempts. You don’t have to wait — you can unlock the account via CLI:
bin/magento admin:user:unlock newadmin
❌ Deleting an Admin User
Magento 2 does not provide a CLI command to delete an admin user.
To remove an admin user, you’ll need to run a SQL query directly on the database:
DELETE FROM admin_user WHERE username = 'your_admin_username';
⚠️ Note: Always back up your database before running direct SQL commands.
🧠 Why Use CLI for Admin Tasks?
Using the CLI to manage admin users can save time, especially when:
- You’re locked out of the admin panel.
- The site is under maintenance.
- You’re working in a headless or SSH-only environment.
- Automating Magento tasks with deployment scripts or Docker containers.
🛠 Bonus: List All CLI Commands
Want to explore more Magento 2 commands? Run:
bin/magento list
This will display all available CLI tools, grouped by category.
🏁 Conclusion
Magento 2’s CLI is a powerful tool for developers and sysadmins. Whether you’re creating a new user, resetting a password, or unlocking access, these commands help you avoid downtime and regain control of your admin panel quickly.
By mastering a few simple lines in the terminal, you can handle urgent admin tasks confidently — without logging into the backend UI at all.