I want to update or reset the admin password for a WordPress website hosted on Amazon Lightsail.
Resolution
To update or reset the admin password for your WordPress site, log in to Lightsail, then use either of these methods:
- Use the wp user update command.
- Configure the wp-config.php file.
After the password is updated, verify that the change is in effect.
Log in to Lightsail, and then switch to the root user
- Use SSH to connect to Lightsail.
- Switch to the root user:
~$ sudo su
Use the wp user update command to update the password
Prerequisite: Make sure that WordPress CLI is installed on your instance. If WordPress CLI is not installed, then configure the wp-config.php file to update the admin password.
-
List your site's users:
# wp user list
-
In the output, note the ID number of the user that requires an updated password.
-
Update the password. Replace example_ID with the ID number that you noted in step 2, and example_password with the new password:
wp user update example_ID --user_pass=example_password
After you change the password, a Success: Updated example_ID notification appears in the output. You can safely ignore the sendmail: not found notification in the output.
Configure the wp-config.php file to update the password
-
Retrieve the database's user name and password. Replace example_path with the path that corresponds to your Lightsail instance:
Note: The output lists the database user's user name and password, not the admin's user name and password.
# egrep -i "DB_USER|DB_PASSWORD" /example_path/wordpress/wp-config.php
-
In the output, note the DB_USER and DB_PASSWORD. The password is a long hash string. Make sure that you copy the entire password.
-
Back up the database. Replace the example_ values with the DB_USER and DB_PASSWORD from step 2:
# mariadb-dump --all-databases user=example_DB_USER --password=example_DB_PASSWORD > /tmp/dbbkp
To restore your database from this backup, run the following command:
# mariadb-dump --all-databases --user=example_DB_USER --password=example_DB_PASSWORD < /tmp/dbbkp
-
List your site's users from the database. Replace the example_ values with the DB_USER and DB_PASSWORD from step 2:
# mariadb --user=example_DB_USER
--password=example_DB_PASSWORD -D bitnami_wordpress -e "select * from
wp_users ;
-
In the output, note the ID number of the user that requires an updated password.
-
Update the password. Replace the example_ values with the DB_USER and DB_PASSWORD that you noted in step 2, and the ID number that you noted in step 5. Replace new_password with your new password:
## mariadb --user=example_DB_USER --password=example_DB_PASSWORD -D bitnami_wordpress -e
"update wp_users set user_pass = MD5('new_password') WHERE ID = 'example_ID' ;"
Verify that the admin password is updated
- Open the WordPress Admin Dashboard at http://example/wp-admin/. Replace example with the IP address of your site.
- Enter the admin user name and your new password.
- Log in.
If you can log in, then the password is updated.