Skip to content

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.

  1. 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.
    1. open the file app\etc\env.php
    2. Goto crypt section and copy the key value. ( check the image below)
      reset magento-2 admin password
  2. Preparing the SQL
    1. In below sql query,
      1. Replace xxxxxxx with the crypt key from step 1
      2. Replace YourNewPassword with your new password.
      3. Replace admin with your admin username ( if its changed from admin)
      4. 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‘;
         
  3. Now you have two options to execute this query against your database.
    1. Via CLI/command prompt/terminal
      1. Login to Mysql using the below command
        mysql -u root -p ( enter mysql password when prompted
      2. select your database
        use your_database_name;
      3. Paste the query and press enter
    2. Via PHPMyAdmin
      Paste the query in the PHP myAdmin SQL tab and execute.
  4. Log in to the Magento admin using the new password! that’s it!

[/vc_column_text][/vc_column][/vc_row]