How to organize massive passwords change on cpanel server?

ATsukanov

Registered
Nov 22, 2004
3
0
151
I need to change all passwords for user account on cpanel server. Is it possible to do it automatically by using some cpanel script? Also I need this information stored in one file in order to know new passwords.

Thanks!
 

elleryjh

Well-Known Member
Apr 12, 2003
479
0
166
You want to change all user accounts' passwords, right?


You can change an account's password by loading the URL

http://root:<rootpass>@domain:2087/scripts/passwd?user=<username>&password=<password>

So, if you have a PHP script with the passwords like this:

PHP:
$userpass = array("user1" => "pass1", "user2" => "pass2");
Then you can automate it like this running php on the same server:

PHP:
foreach($userpass as $user=>$pass){
file_get_contents("http://root:<rootpass>@localhost:2087/scripts/passwd?user=$user&password=$pass");
}
And some caviats....

It requires fopen url wrappers. If not enabled, use curl, etc.

Having the root password in plaintext is dangerous, so make sure this file is not world readable, and delete it afterwards.

The foreach loop doesn't check for success or anything, so if you have an invalid account or empty password, it won't tell you.