One place for hosting & domains

      How to Reset a WordPress Admin Password Via the Command Line Using WP-CLI



      Part of the Series:
      Common WordPress Errors

      This tutorial series explains how to troubleshoot and fix common errors that you may encounter when deploying, maintaining, and updating your WordPress installation.

      Each tutorial in this series includes descriptions of common deployment, maintenance, or update errors, and explores ways to fix and optimize your installation to scale.

      Introduction

      In WordPress, oftentimes one of the most important pieces of information that is forgotten or misplaced is the admin password.

      In this tutorial, learn how to retrieve or reset your WordPress admin password from the command line using WP-CLI, a tool that allows users to manage WordPress blogs from a terminal.

      Prerequisites

      To follow this guide, you’ll need:

      • Access to a server as a regular system user with sudo privileges. You can follow one of our initial server setup guides to set this up.
      • A PHP environment running along a web server, with either Apache or Nginx. To set this up, you can follow either one of these tutorials:
      • A WordPress blog installed and secured. To set this up, you can follow either one of these tutorials, depending on which server you chose to use:
      • WP-CLI installed on your local machine or development server. To install WP-CLI, follow step 1 of our tutorial on “How To Manage Your WordPress Site From the Command Line”

      Step 1 — Resetting Your WordPress Admin Password via WP-CLI

      WP-CLI is a utility that allows you to perform administrative tasks via the command line. In this step, you’ll use the WP-CLI utility to reset your WordPress admin password.

      After you have successfully installed WP-CLI, navigate to your main WordPress directory:

      Next, you’ll grab a list of the users that are authorized to edit your WordPress site:

      Output

      Once the list is produced, locate the name and user ID of the admin user whose password you’d like to reset. To update the password for the user selected, enter the following, replacing the highlighted password with a secure password of your own choosing:

      • wp user update 1 --user_pass=password

      Your WordPress admin password should now be changed. In the next step, we’ll test the changes to ensure that your new admin password has been applied.

      Step 2 — Testing Your WordPress Admin Password

      After setting up a new admin password via WP-CLI, it’s a good idea to test the changes to be sure the password was applied correctly. To test your password, log in to the WordPress admin panel at https://yoursite.com/wp-admin, replacing the highlighted text with your website’s domain name or IP address.

      If you are able to log into your WordPress dashboard, you’ve successfully changed your WordPress admin password via WP-CLI. If you’ve encountered an error, repeat Step 1 using a new password, then attempt to log in again.

      Conclusion

      In this tutorial, you used the WP-CLI utility to update your admin password. For more comprehensive information about WordPress, visit our list of WordPress resources.



      Source link