Page 1 of 1

How to edit or create admin account on WordPress website using WP-CLI

Posted: Thu Nov 17, 2022 12:04 pm
by isscbta
WP-CLI is a text-based command-line interface for interfacing with your WordPress site directly. With no web browser required, it is easy to update plugins, set up multisite installations, and configure other things.

To list all the commands write “wp help” or just “wp”.

In this post, we will cover use cases where you need to edit or create a new admin account.

As root in SSH run:

Download wp-cli:

Code: Select all

wget -nv https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/local/bin/wp
chmod +x /usr/local/bin/wp
Define username of hosting account and go to public_html folder:

Code: Select all

USER='SomeMyVestaUser'
cd /home/SomeMyVestaUser/web/domain.com/public_html/
To list all admin accounts:

Code: Select all

sudo -H -u$USER wp user list --role=administrator
Output was:

Code: Select all

# +----+------------+--------------+-----------------+---------------------+---------------+
# | ID | user_login | display_name | user_email      | user_registered     | roles         |
# +----+------------+--------------+-----------------+---------------------+---------------+
# | 1  | admin      | admin        | [email protected] | 2022-07-07 08:47:16 | administrator |
# +----+------------+--------------+-----------------+---------------------+---------------+
Set new pass (in this example administrator account is 'admin'):

Code: Select all

sudo -H -u$USER wp user update admin --user_pass="HfrhnbAdQCOzHxpK"
Or create new administrator account:

Code: Select all

sudo -H -u$USER wp user create 'mynewadmin' '[email protected]' --role=administrator --user_pass=HfrhnbAdQCOzHxpK
Don't use the password from this example, please generate a new one.