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]