Update All cPanel Passwords

Upon request of changing all the passwords on a server, we created a script to change all the passwords on a cPanel server. This script enables passwords to be changed from the command line, sends a list of users to a text file, generates a random 10 character password, saves the new passwords to a file, and updates all FTP/MySQL/cPanel passwords for the users. Although passwords should be changed through WHM, this allows you to change hundreds of passwords within a few seconds.

#Changes every cPanel password on the server and stores the credentials in ~/newCredentials
#$newPassword is a randomly generated password with 10 characters
ls -la /home | awk ‘{print $3}’ | grep -v root | grep -v wheel | grep -v cpanel | grep -v apache | grep -v csf | grep -v ‘^$’ > /tmp/usersforchpass
for i in `more /tmp/usersforchpass `
newPassword=$(</dev/urandom tr -dc ‘A-Za-z0-9’ | head -c10)
echo “Username: $i” >> ~/newCredentials
echo “Password: $newPassword” >> ~/newCredentials
echo “” >> ~/newCredentials
/scripts/chpass $i $newPassword
/scripts/mysqlpasswd $i $newPassword
rm -f /tmp/usersforchpass