$100 Website Offer

Get your personal website + domain for just $100.

Limited Time Offer!

Claim Your Website Now

Step-by-Step Tutorial: Reset WordPress Admin Password Using WP-CLI Commands

What is WP-CLI?

WP-CLI is the command-line tool for managing WordPress without opening the browser. You can manage users, plugins, themes, database, cache, posts, and even reset user passwords from terminal. WordPress.org describes WP-CLI as a scriptable way to perform WordPress admin tasks from the command line. (WordPress.org 日本語)

This tutorial explains how to reset a WordPress admin password using wp commands.


1. Login to Your Server

Connect to your server using SSH.

ssh username@your-server-ip

Example:

ssh root@188.xxx.xxx.xxx

Or, for cPanel user:

ssh mycpaneluser@your-server-ip

2. Go to Your WordPress Installation Directory

You must run WP-CLI from the WordPress root directory, where wp-config.php exists.

Example paths:

cd /home/username/public_html

or:

cd /var/www/html

or:

cd /opt/lampp/htdocs/mywordpress

Check if this is the correct WordPress directory:

ls -l

You should see files like:

wp-config.php
wp-admin
wp-content
wp-includes

3. Check WP-CLI Is Working

Run:

wp --info

Then check WordPress core status:

wp core version

If you are logged in as root, WP-CLI may block execution. Better method is to run as the website owner:

sudo -u username wp core version

Example:

sudo -u mycpaneluser wp core version

Emergency method only:

wp core version --allow-root

4. List WordPress Users

Run:

wp user list

The official WP-CLI wp user list command shows user fields such as ID, user login, display name, email, registration date, and roles. (WordPress Developer Resources)

Example output:

+----+------------+--------------+----------------------+---------------------+---------------+
| ID | user_login | display_name | user_email           | user_registered     | roles         |
+----+------------+--------------+----------------------+---------------------+---------------+
| 1  | admin      | Admin        | admin@example.com    | 2024-01-01 10:00:00 | administrator |
| 2  | rajesh     | Rajesh Kumar | rajesh@example.com   | 2024-02-01 12:00:00 | administrator |
+----+------------+--------------+----------------------+---------------------+---------------+

To show only administrators:

wp user list --role=administrator

To show only useful columns:

wp user list --role=administrator --fields=ID,user_login,user_email,roles

5. Reset Admin Password Using User ID

The main command is:

wp user update USER_ID --user_pass='NEW_PASSWORD'

WP-CLI officially supports wp user update for updating an existing user, and the --user_pass=<password> option is used to set the plain text password for that user. (WordPress Developer Resources)

Example:

wp user update 1 --user_pass='MyNewStrongPassword@123'

Expected output:

Success: Updated user 1.

Now you can login to WordPress admin:

https://yourdomain.com/wp-admin

6. Reset Password Using Username

You can also reset password using the WordPress username.

wp user update admin --user_pass='MyNewStrongPassword@123'

Example:

wp user update rajesh --user_pass='Rajesh@Secure2026'

7. Reset Password Using Email Address

WP-CLI also allows user login, email, or ID as the user identifier for wp user update. (WordPress Developer Resources)

Example:

wp user update rajesh@example.com --user_pass='NewPassword@2026'

8. Safer Method: Avoid Showing Password in Command History

Directly typing password in command may save it in shell history. Better approach:

read -s WP_NEW_PASS

Type the password and press Enter. It will not display on screen.

Then run:

wp user update admin --user_pass="$WP_NEW_PASS"

Clear the variable:

unset WP_NEW_PASS

Example full flow:

cd /home/username/public_html

wp user list --role=administrator --fields=ID,user_login,user_email,roles

read -s WP_NEW_PASS

wp user update admin --user_pass="$WP_NEW_PASS"

unset WP_NEW_PASS

Nice and clean. No password sitting in your terminal history like a banana peel waiting for future trouble.


9. If WP-CLI Says “Error: This does not seem to be a WordPress installation”

This means you are not inside the correct WordPress directory.

Find wp-config.php:

find /home -name wp-config.php 2>/dev/null

Example output:

/home/example/public_html/wp-config.php

Then go there:

cd /home/example/public_html

Run again:

wp user list

10. If You Have Multiple WordPress Sites

Use the --path option.

wp --path=/home/example/public_html user list

Reset password:

wp --path=/home/example/public_html user update admin --user_pass='NewPassword@2026'

Example for addon domain:

wp --path=/home/example/addon-domain.com user update rajesh --user_pass='StrongPass@2026'

11. If You Are Using cPanel

Usually WordPress path is:

/home/cpaneluser/public_html

Run as the cPanel user:

sudo -u cpaneluser -i
cd /home/cpaneluser/public_html
wp user list
wp user update admin --user_pass='NewPassword@2026'

Or from root:

sudo -u cpaneluser wp --path=/home/cpaneluser/public_html user update admin --user_pass='NewPassword@2026'

12. If You Are Using XAMPP / LAMPP

Example:

cd /opt/lampp/htdocs/mywordpress
wp user list
wp user update admin --user_pass='NewPassword@2026'

If running as root:

wp user update admin --user_pass='NewPassword@2026' --allow-root

Better:

chown -R daemon:daemon /opt/lampp/htdocs/mywordpress
sudo -u daemon wp --path=/opt/lampp/htdocs/mywordpress user update admin --user_pass='NewPassword@2026'

13. Create a New Admin User If Existing Admin Is Broken

Sometimes resetting password is not enough because the admin user may be corrupted, deleted, or has wrong role.

Create a new admin user:

wp user create newadmin newadmin@example.com --role=administrator --user_pass='StrongPassword@2026'

Example:

wp user create rajeshadmin rajesh@example.com --role=administrator --user_pass='Rajesh@Admin2026'

Verify:

wp user list --role=administrator

14. Set Existing User as Administrator

If user exists but role is not administrator:

wp user set-role USERNAME administrator

Example:

wp user set-role rajesh administrator

Or using user ID:

wp user set-role 2 administrator

Verify:

wp user list --fields=ID,user_login,user_email,roles

15. Recommended Full Safe Command Flow

Use this when you forgot WordPress admin password:

cd /home/username/public_html

wp core version

wp user list --role=administrator --fields=ID,user_login,user_email,roles

read -s WP_NEW_PASS

wp user update admin --user_pass="$WP_NEW_PASS"

unset WP_NEW_PASS

wp user list --role=administrator --fields=ID,user_login,user_email,roles

If username is not admin, replace it with correct username:

wp user update rajesh --user_pass="$WP_NEW_PASS"

16. Common Errors and Fixes

Error: wp: command not found

WP-CLI is not installed or not in PATH.

Check:

which wp

If nothing returns, install WP-CLI or use full path if your hosting provides it.


Error: This does not seem to be a WordPress installation

You are in the wrong directory.

Fix:

find /home -name wp-config.php 2>/dev/null
cd /path/where/wp-config-exists

Error: Error establishing a database connection

WordPress cannot connect to DB. Check wp-config.php:

cat wp-config.php | grep DB_

Then test:

wp db check

Error: YIKES! It looks like you're running this as root

Better run as site user:

sudo -u username wp user list

Temporary emergency method:

wp user list --allow-root

Error: Permission denied

Fix ownership according to your hosting user.

Example:

chown -R username:username /home/username/public_html

Then run:

sudo -u username wp user list

17. Security Tips After Reset

After login, do these:

wp user list --role=administrator

Remove unknown admin users:

wp user delete suspiciousadmin --reassign=admin

Change your password again from WordPress dashboard if needed.

Update plugins and themes:

wp plugin update --all
wp theme update --all

Check WordPress core:

wp core verify-checksums

Flush cache:

wp cache flush

Final Quick Commands

Reset by username:

wp user update admin --user_pass='NewPassword@2026'

Reset by user ID:

wp user update 1 --user_pass='NewPassword@2026'

Reset by email:

wp user update admin@example.com --user_pass='NewPassword@2026'

List admins:

wp user list --role=administrator

Create new admin:

wp user create newadmin newadmin@example.com --role=administrator --user_pass='StrongPassword@2026'

Set user as admin:

wp user set-role rajesh administrator

Best safe password reset:

read -s WP_NEW_PASS
wp user update admin --user_pass="$WP_NEW_PASS"
unset WP_NEW_PASS

Related Posts

Website Contact Page Design: Best Practices for Usability, Trust, and Conversions

Introduction A website contact page is often the final destination before a prospect decides whether to do business with you. Potential buyers navigate through your service pages,…

Read More

Smart Travel Connectivity: How to Evaluate Data, Networks, and Roaming Plans

Introduction Stepping off an international flight without internet access creates immediate hurdles. Modern travelers depend on connected phones to hail airport rides, check digital boarding passes, navigate…

Read More

Mautic vs listmonk vs Dittofeed — Complete Self-Hosted Marketing Automation Comparison

For your requirements—automatic lead capture, centralized contacts, segmentation, Amazon SES, WhatsApp bulk campaigns, automated follow-ups, low operating costs, and complete data ownership—Mautic is my first recommendation. However,…

Read More

Global Mobile Network Identifiers: A Practical Guide to Telecom Codes and Provider Records

Introduction Every time a mobile phone connects to a cellular tower, a quiet digital handshake takes place. Whether a smartphone is roaming in a foreign airport, an…

Read More

Optimizing Reservations, Waitlists, and Walk-Ins for Independent Dining Rooms

Introduction Running a busy dining room requires careful coordination between the front-of-house staff, the kitchen team, and arriving guests. When a restaurant relies on paper books or…

Read More

Turning Clicks into Clients: The Power of Effective Service Pages

Introduction Driving traffic to a business website is only half the battle. Many business owners invest heavily in digital marketing, social media, and search engine optimization, only…

Read More
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x