Samba4 – Setting up user password change

jovem redefinindo senha no laptop durante o trabalho
Share

This script allows you to configure all Samba4 users to change their password at first login.

To execute the steps in this article, you must already have Samba4 set up and running as a domain controller. We have created a comprehensive article showing how to install and configure Samba4.

See the article “Configuring Samba as a Domain Controller.”

With Samba4 prepared, follow the steps below:

Step 1

Create the file set_passwords.sh.

Step 2

Edit the file and add the following content:

#!/bin/bash

list="$(samba-tool user list | egrep -v 'Administrator|Guest|krbtgt')"

for user in ${list[@]}; do
        samba-tool user setpassword $user --newpassword Pass$123 --must-change-at-next-login
done

All Samba4 users except for the Administrator, Guest, and krbtgt users, which should not be included, will have their password changed to force password change at the next login.

Step 3

Save the file and change the file’s execution permission with the following command:

chmod a+x set_passwords.sh

Step 4

Execute the script with the command:

./set_passwords.sh

Step 5

Check the command output to see if the passwords were successfully changed. The output should appear as in the image:

resultado da execução de script no terminal linux

Done! At the next login for each user, the password change will be requested.

Leave a Reply

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