InMotion Hosting Support Center

Part of regular WordPress maintenance is password rotation. Once in a while, it is best advised to update your WordPress password. In this article, we'll show you how you can create a script to automate WordPress password rotation process and send you an email with the new password.

WordPress Auto Password Rotation Script

In order to complete this tutorial, you will need access to your cPanel. Follow along with the steps below:

  1. Log into cPanel
  2. Under Files choose File Manager
  3. Navigate to the directory that contains your WordPress site files
  4. Create a new file called
  5. Edit the file
  6. Paste the following into the file:
    RANDPW="$(tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1)"
    wp user update 1 --user_pass=$RANDPW &&
    mail -s "New Password for WordPress" $EMAIL <<< $RANDPW
  7. Substitute with your desired email address (this will be used to receive the new WordPress password)
  8. Likewise, be sure to check the number following wp user update to make sure it corresponds with the correct WordPress user ID
  9. If you are unsure which number has been assigned to your WordPress user, run this command via ssh:
    wp user list
    (Use the number that corresponds with the user account you are trying to update)
  10. Change file permissions on to 755, or, if you are in SSH, you can run the following command to make this script executable:
    chmod +x

Now, all you need to do is set up a cron job to run this script at your decided interval. Then, you can also check to see if the cron job is running correctly.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved. Please click the button below to be redirected to the login page.

Post a Comment

Email Address:
Phone Number:

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!