Added reset password

This commit is contained in:
Douglas Barone 2023-02-28 14:59:52 -04:00
parent 99e46a4d1f
commit cd2e06b74f
2 changed files with 26 additions and 0 deletions

0
pdc-bulk-del-user.sh Normal file → Executable file
View File

26
pdc-reset-password.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
USERNAME=$1
PASSWORD=123456789
# Check if arguments are not empty
if [ -z "$USERNAME" ]; then
echo "Usage: $0 <username>"
exit 1
fi
# Check if $USERNAME exists
if ! samba-tool user show $USERNAME >/dev/null 2>&1; then
echo "User $USERNAME do not exists"
exit 1
fi
# Set user password
echo "Setting user password $PASSWORD for user $USERNAME"
# Set user password with smbpasswd, inject password and password confirmation into stdin
echo -e "$PASSWORD\n$PASSWORD" | smbpasswd -s -a $USERNAME >>/var/log/samba/smbpasswd.log 2>&1
# Force password change on next login
echo "Forcing password change on next login for user $USERNAME"
net sam set pwdmustchangenow $USERNAME yes >>/var/log/samba/smbpasswd.log 2>&1