BLOG

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.

#!/bin/bash
#Changes every cPanel password on the server and stores the credentials in ~/newCredentials
#$newPassword is a randomly generated password with 10 characters
export ALLOW_PASSWORD_CHANGE=1
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 `
do
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
done
/scripts/ftpupdate
rm -f /tmp/usersforchpass

Pastebin:
http://pastebin.com/raw.php?i=XfMEet9y

Leave a Reply

Your email address will not be published. Required fields are marked *