$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

The Comprehensive Blueprint for Free Vehicle Rental Management Software

Introduction The growth of the global vehicle rental industry has been fueled by a shift in consumer behavior toward the sharing economy. As travel demands rise and…

Read More

Comparing the World’s Best Heart Surgery Hospitals and Clinical Teams

Introduction The Growing Burden of Cardiovascular Diseases Cardiovascular diseases (CVDs) remain the leading cause of mortality globally, placing an unprecedented burden on healthcare delivery systems. Ischemic heart…

Read More

Affordable Website Design for Growing Companies: The Complete Strategic Guide

Introduction In the digital landscape, a website serves as a company’s modern storefront, primary lead generator, and foundational brand asset. For growing companies, startups, and small businesses,…

Read More

The Ultimate Guide to a User-Friendly and Mobile-Ready Business Website

Introduction A corporate website is no longer just a passive digital brochure; it functions as your primary storefront, lead generator, and brand ambassador. Over 60% of all…

Read More

Best Places to Visit in Goa: The Ultimate Travel Guide to Beaches, Nightlife & Itineraries

Introduction Finding the best places to visit in Goa means opening the door to a paradise that seamlessly blends laid-back coastal living with high-octane excitement. Whether you…

Read More

Best Countries for Plastic Surgery: Top Global Cosmetic Hospitals, Surgeons, and Costs

Introduction Deciding to undergo an aesthetic procedure is a deeply personal journey, and finding the best cosmetic hospitals in the world is the critical first step toward…

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