How to Change WordPress user Password via SSH commands?

Changing a WordPress user password via SSH in a DigitalOcean droplet running a LAMP stack involves a few steps. You’ll be interacting with the MySQL database directly, so it’s important to be careful to avoid unintended changes. Here’s a step-by-step guide:

  1. Connect to Your Droplet via SSH:
    Open your terminal or command prompt and use the SSH command to connect to your droplet. It typically looks like this:
   ssh username@your_droplet_ip

Replace username with your SSH user and your_droplet_ip with your droplet’s IP address.

  1. Access MySQL:
    Once connected, you need to access MySQL. The command usually looks like this:
   mysql -u root -p

If you’re not using the root user or if your database user is different, replace root with your MySQL username. After entering this command, you’ll be prompted for the MySQL password.

  1. Identify the WordPress Database:
    If you’re not sure what your WordPress database is called, you can list all databases with:
   SHOW DATABASES;

Look for something that seems like it would be your WordPress database (often it’s named wordpress, wp, or something similar).

  1. Use the WordPress Database:
    Once you’ve identified the database, switch to it using:
   USE database_name;

Replace database_name with the name of your WordPress database.

  1. Update the User Password:
    WordPress uses the MD5 hash to store passwords. You’ll need to update the password using an MD5 hash. First, identify the user whose password you want to change:
   SELECT ID, user_login FROM wp_users;

Then, update the password with:

   UPDATE wp_users SET user_pass = MD5('new_password') WHERE user_login = 'your_username';

Replace new_password with your new desired password and your_username with the WordPress username.

  1. Exit MySQL and SSH:
    After updating the password, exit MySQL by typing exit, then disconnect from SSH by typing exit again.

A few important notes:

  • Be sure to replace placeholders (like your_username, new_password, database_name) with your actual details.
  • The WordPress database tables might have a different prefix instead of wp_, so adjust your commands accordingly.
  • Always back up your database before making direct changes as a precaution.

Remember, working directly with the database can be risky, so make sure you are confident in what you are doing or seek assistance from someone who is.