Magento 2 How to reset admin password using CLI / Command Prompt / Terminal in Linux
Let's see how we can reset Magento 2 admin password in Linux using CLI / command prompt or terminal.Getting the cryptographic saltMagento 2 passwords are stored after scrambling with the cryptographic salt which is defined in the app\etc\env.phpSo first we need to copy that.open the file app\etc\env...
Amila Rajapaksha is the CEO and Managing Director of Mobiz International (Pvt) Ltd, a web design and development company based in Gampaha, Sri Lanka. Since 2010 he has helped businesses across Sri Lanka and overseas launch fast, search-friendly websites and online stores — working hands-on with WordPress, Magento and custom Laravel builds, and the SEO that makes them rank.
Let's see how we can reset Magento 2 admin password in Linux using CLI / command prompt or terminal.
- Getting the cryptographic salt
Magento 2 passwords are stored after scrambling with the cryptographic salt which is defined in the app\etc\env.php
So first we need to copy that.- open the file app\etc\env.php
- Goto crypt section and copy the key value. ( check the image below)
- Preparing the SQL
- In below sql query,
- Replace xxxxxxx with the crypt key from step 1
- Replace YourNewPassword with your new password.
- Replace admin with your admin username ( if its changed from admin)
- if you your magento 2 installation uses a table_prefix , please add that infront ofadmin_user
UPDATE admin_userSET password = CONCAT(SHA2('xxxxxxxYourNewPassword', 256), ':xxxxxxx:1') WHERE username = 'admin';
- In below sql query,
- Now you have two options to execute this query against your database.
- Via CLI/command prompt/terminal
- Login to Mysql using the below command
mysql -u root -p ( enter mysql password when prompted - select your database
use your_database_name; - Paste the query and press enter
- Login to Mysql using the below command
- Via PHPMyAdmin
Paste the query in the PHP myAdmin SQL tab and execute.
- Via CLI/command prompt/terminal
- Log in to the Magento admin using the new password! that's it!
[/vc_column_text][/vc_column][/vc_row]
Related Articles
AI Personalization for WooCommerce | Sri Lankan Retailers Guide
Bridging Continents: The New Frontier for Sri Lankan Retailers
How to Retain Customers in Sri Lanka's Booming Ecommerce Landscape: Proven Strategies for 2026
Discover Sri Lanka-specific strategies to retain ecommerce customers amid a $2.65B market boom. Learn mobile-first tactics, trust-building, and hyperlocal tips for platforms like WooCommerce and Shopify in 2026.
Enable or Disable Magento 2 Maintenance Mode using CLI / Command Prompt or Files
What is the magento maintenance mode ?When Magento is in maintenance mode, visitors see a Service Temporarily Unavailable message in their web browsers instead of the store. However, authorized IP addresses can still view the store normally.You can enable maintenance mode using two methods.How to en...
Magento 2 Modes Explained | Developer & Production Setup
Display the current mode in Magento 2 using CLI/Command Promptbin/magento deploy:mode:showThis will result in something like belowCurrent application mode: {mode}.Set/Change mode in Magento 2 using CLI/Command Promptbin/magento deploy:mode:set {mode}{mode} can be either default, developer, or produc...