Resetting your WordPress login through the shell can be done with the MySQL command-line client mysql or by using the wp-cli command, a small but handy program to manage WordPress instances on the shell.
Using the mysql command to set a new WordPress password
The first step is to log into your server via SSH. Before changing the password in the database, you should check that you have a recent backup of the database, just in case something goes wrong.
Use the MySQL command line tool to connect to the MySQL or MariaDB server:
mysql -u username -p
Replacing username with your MySQL username. You’ll be prompted to enter your password.
Once you are logged into MySQL, you need to select your WordPress database:
use wordpress_db;
Replace `wordpress_db` with your database name.
Then you must execute an SQL query to update the user password. WordPress uses the MD5 hashing algorithm:
UPDATE `wp_users` SET `user_pass` = MD5('newpassword') WHERE `user_login` = 'yourusername';
Replace newpassword with your new desired password and yourusername with your WordPress username.
Type:
exit
to leave the MySQL prompt.
Update the WordPress Admin Password with wp-cli
Using wp-cli command is even easier to reset the WordPress administrator password.
The first step is to log into your server using SSH. If you have not installed wp-cli yet, follow these instructions.
Then use the wp-cli command to reset the password:
wp user update username --user_pass=newpassword
Replace username with your WordPress username and newpassword with your new password.