The other day I needed to change passwords for multiple cPanel accounts. Since there was a lot accounts in question, changing passwords manually was out of the question. Changing passwords from shell using passwd utility was also out of the question because that would change only the password for Unix user - MySQL and FTP passwords would remain unchanged. In the end I wrote a simple script which automates changing system, FTP and MySQL passwords for cPanel user.
The script allows you to either specify the new password for each account or generate a random one. So, if you want to change passwords for multiple cPanel accounts and set your own passwords, you will need to put the list of usernames and their passwords into a text file with the following format:
user1 password1 user2 password2 userN passwordN
Afterwards you can run the script with the following command:
# ./cpanel-chpasswd --no-random /path/to/credentials_file
If you don’t want to specify new passwords, you can let the script to generate random passwords. In this case, you’ll need to put all usernames into text file (one username per line) and run the script with the following command:
# ./cpanel-chpasswd --random /path/to/credentials_file
While the script executes, its output will be printed on stdout. Since the new passwords will be printed on stdout as well, you will probably want to redirect the output to an file on disk, just to have all the changes that were made on record.
You can download cpanel-chpasswd script or copy it from bellow.
Update: As Branko Toić commented bellow, to change passwords from command line instead from WHM, in newer cPanel versions it’s necessary to export
ALLOW_PASSWORD_CHANGE variable. The script in this tutorial, as well as the one available for download is updated to meet this requirement.