How to Change WordPress Password Using WP-CLI


Previously, we have already covered five ways to change the password in WordPress, and in this article, we will tell you how to do it using the WP-CLI utility. Please note that if none of the previously suggested methods helped you for some reason, then WP-CLI is unlikely to work magic for you in this regard.

WP-CLI utility

WP-CLI is a command-line WordPress installation management utility, and in recent years more and more hosting providers have started to support it. It is convenient to manage plugins, themes, posts, media files, and of course users.

You can check if the utility is installed using the command wp cli info, which will display the utility version, PHP version, and other information. By the way, if your hosting provider has not pre-installed the utility, but you have SSH access to your account, then you can try to install it yourself, as described in this article.

User management

The WP-CLI provides a large number of commands for managing users, including managing their roles and privileges, creating, updating, and deleting users, importing, searching, and more.

Also see: Five New Starter Themes on WordPress

With the update user command, you can change its password:

wp user update username --user_pass=newpassword

Where username is the username and new password is the new password. If the new password contains spaces or any special characters, it must be enclosed in quotation marks. If you have forgotten your username, you can view the entire list with the command:

wp user list

If you’re working on someone else’s WordPress installation and need admin access, then changing someone else’s passwords isn’t the best option, and asking users to reveal their password to you is not safe. In this case, it is better to create a new temporary administrator:

wp user create newusername --role=administrator --user_pass=newpassword

And after doing all the necessary work, do not forget to delete it:

wp user delete newusername

By the way, it is strange that some hosting companies support employees, having full access to your server, still ask you to provide them with the administrator password in cleartext. We advise you to stay away from these.

Leave a comment

Your email address will not be published. Required fields are marked *