Created by Daniel on 11/22/2024
We have all been in this situation. We got SSH access but we cannot decrypt the current admin password from the database. Now we need to create an admin user via a raw sql query (like in wordpress). Magento 2 has an option for this in the command line interface.
First, connect to SSH so you can have a shell.
ssh [email protected]
After this, navigate to your magento root folder (in our case this is magento2, but this could also be www or public_html, depending on your setup).
cd magento2
Now we can use this oneliner (replace the values with yours).
php bin/magento admin:user:create --admin-user=daniel --admin-password=DanielKnows1 --admin-email=daniel@da
After pressing enter, the command should report something like this.
Created Magento administrator user named daniel
If you get this error, your password is not complex enough. Magento2 requires both numeric and alphabetic characters.
Your password must include both numeric and alphabetic characters
If you want to know more about this command, you can use this
php bin/magento admin:user:create --help