It happens to all of us at some point or another – especially when doing development work – you find yourself locked out of your WordPress site with no way to change or reset your admin password. What do you do in that situation?
Here is a way you can update your password (and other aspects of your account) directly from the command line.
Note that this article assumes that you already have a “SSH” or “shell” account from your hosting provider and that WP-CLI (the WP Command Line Interface) is already installed, either by you or by your host. Quite a few hosts are installing WP-CLI by default now, so you probably already have access to this powerful WP management tool without needing to install it yourself.
Log into your shell account and, if your login doesn’t take you to the specific WP site root, change the directory to the root of the site you are working with.
Before we change the password, I want to show you that if you forget commands in WP-CLI, you can get a list of them easily. For changing the password, we’ll be using the “user” command, so enter “wp user” at the command line to get a list of possible actions you can complete:
This shows you all of the possible user commands. The last one – “update” – is what we need to change the password, and it shows you that you need to enter the following:
wp user update the_username --user_pass=your_new_password
Our test user account we want to change is “1atest” and we’ll be setting the password to “mynewpass” (just by way of example). Enter the following at the command line:
Upon successful update, you’ll get a success message (which will display the user ID that was updated):
That’s it! You’ve updated your user password via the command line and can now log into the site.