How to edit or create admin account on WordPress website using WP-CLI
Posted: Thu Nov 17, 2022 12:04 pm
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:
Define username of hosting account and go to public_html folder:
To list all admin accounts:
Output was:
Set new pass (in this example administrator account is 'admin'):
Or create new administrator account:
Don't use the password from this example, please generate a new one.
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
Code: Select all
USER='SomeMyVestaUser'
cd /home/SomeMyVestaUser/web/domain.com/public_html/
Code: Select all
sudo -H -u$USER wp user list --role=administrator
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 |
# +----+------------+--------------+-----------------+---------------------+---------------+
Code: Select all
sudo -H -u$USER wp user update admin --user_pass="HfrhnbAdQCOzHxpK"
Code: Select all
sudo -H -u$USER wp user create 'mynewadmin' '[email protected]' --role=administrator --user_pass=HfrhnbAdQCOzHxpK