Skip to main content

How to Reset a WordPress Admin Password Using Linux, AWS Lightsail, or WP-CLI

If you’ve ever found yourself locked out of your WordPress admin dashboard, you know how frustrating it can be. Whether you’ve forgotten your password, a user account got compromised, or you simply need to reset it for security reasons, knowing how to reset your WordPress admin password is essential. Here’s a straightforward guide on how to do it using Linux, AWS Lightsail, Bitnami WordPress, or WP-CLI.

Why Would You Need to Reset a WordPress Admin Password?

There are several scenarios where you might need to reset your WordPress admin password:

  • Forgotten Password: It happens to the best of us. You try to log in, but the password just isn’t coming to you.
  • Security Breach: If you suspect that your admin account has been compromised, resetting the password is a crucial step.
  • User Account Management: Sometimes, you might need to reset the password for another admin or user account.

In these situations, having a reliable method to reset the password can save you a lot of time and hassle.

Method 1: Resetting via WP-CLI

WP-CLI is a powerful command-line tool for managing WordPress installations. If you have it installed, resetting the admin password is quick and easy.

1. Connect to your server:

  • SSH into your server:
    ssh your-username@your-server-ip
  • Connect using SSH from Lightsail:
    • Log in to your AWS Lightsail account.
    • Navigate to your instance and click on Connect using SSH.

2. Navigate to your WordPress directory:

If you’re unsure where your WordPress directory is located, use the cd and ls commands to navigate through your directories and find it.

cd /stack/wordpress/ or use
sudo find / -type d -name wordpress

 

3. List all users to find the admin user ID or username:

wp user list

Example output:

+----+------------+--------------+-------------------+---------------------+---------------+
| ID | user_login | display_name | user_email        | user_registered     | roles         |
+----+------------+--------------+-------------------+---------------------+---------------+
| 1  | admin      | Admin        | admin@example.com | 2020-01-01 00:00:00 | administrator |
| 2  | editor     | Editor       | editor@example.com| 2020-02-01 00:00:00 | editor        |
+----+------------+--------------+-------------------+---------------------+---------------+

4. Reset the password:

wp user update 1 --user_pass="NEWPASSWORD"

Replace NEWPASSWORD with your new password.

Method 2: Resetting via MySQL Database

If you’re comfortable with using MySQL, you can reset the password directly in the database.

1. Connect to your server:

  • SSH into your server:
    ssh your-username@your-server-ip
  • Connect using SSH from Lightsail:
    • Log in to your AWS Lightsail account.
    • Navigate to your instance and click on Connect using SSH.

2. Access MySQL:

mysql -u your-db-username -p your-db-name

3. Select your WordPress database:

USE your-db-name;

4. Update the admin password:

UPDATE wp_users SET user_pass=MD5('NEWPASSWORD') WHERE user_login='admin';

Replace NEWPASSWORD with your new password.

5. Exit MySQL:

EXIT;

Method 3: Resetting via phpMyAdmin

If your hosting provider offers phpMyAdmin, you can use it to reset the password through a graphical interface.

1. Log in to phpMyAdmin through your hosting control panel.

2. Select your WordPress database from the left-hand sidebar.

3. Navigate to the wp_users table.

4. Find the admin user and click Edit.

5. Change the value of user_pass to the MD5 hash of your new password. You can generate an MD5 hash using online tools.

6. Save the changes.

When to Use These Methods

  • WP-CLI: When you have SSH access and are comfortable with command-line tools.
  • MySQL: When you need a direct approach and are familiar with SQL commands.
  • phpMyAdmin: When you prefer a graphical interface and your hosting provider supports it.

By using these methods, you can regain access to your WordPress admin dashboard quickly and securely. Remember, regular password updates and using strong, unique passwords for your admin accounts can greatly enhance your site’s security. Happy blogging!

shivam sagar

Shiv has been working at Brandviser Melbourne as a lead web solution and marketing consultant.

Leave a Reply