Add to Favourites Add to Favourites    Print this Article Print this Article

Change password for all DA users via command line

If, for whatever reason, you wish to change the password for all of your many DA accounts, and there are too many to do manually, you can use the following script to change the password.

1) Prepare the scripts:

cd /root
wget -O change_pass.php http://files1.directadmin.com/services/all/httpsocket/examples/example.change_pass.php
wget http://files1.directadmin.com/services/all/httpsocket/httpsocket.php
chmod 700 change_pass.php

Edit the file change_pass.php and set the $server_pass value to your admin password value.  Also, if you're running DA with https (SSL), set $server_ssl="Y".

With these in place, you can change user passwords one at a time, like this:

./change_pass.php username "password"

where username is the name of the DA User account, and password is the password the User will be set to.  It's imporant to use the API or DA to change User passwords, because DA updates many locations (system, ftp, email, database), which the "passwd" command does not do.


2) Now, to make the above script work on all of your accounts automatically, we'll create another script.
Create the file:

/root/change_all_user_pass.sh

and in it, put the following code:

#!/bin/sh

ADMIN_USER=admin

for i in `ls /usr/local/directadmin/data/users`; do
{
      if [ "$i" = "$ADMIN_USER" ]; then
              continue;
      fi

      PASSWORD=${i}12345
      ./change_pass.php $i "$PASSWORD"
};
done;
exit 0;

Where all DA user passwords will be set to their username followed by 12345, eg... for "bob", the password would be:

bob12345

If you wish for all User accounts to be set to the same password, then set the PASSWORD= value to that single desired password.
Note that the admin account (set to ADMIN_USER) will be skipped, as the change_pass.php script needs to have a correct password all the time.

Save/exit.


3) Run the script:

chmod 755 /root/change_all_user_pass.sh
/root/change_all_user_pass.sh


Keep in mind that this changes the passwords for all DirectAdmin accounts, including the admin account, so take note of the password that's set.


Was this answer helpful?

Also Read