Last active
January 28, 2021 19:24
-
-
Save onstatus/a1280a54cdfa8a93ef8a04ca419e0aea to your computer and use it in GitHub Desktop.
Bash script to reset FreeIPA accounts password. This code assume that admin kerberos ticket is still valid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
[email protected] | |
URL="https://webmail.example.com" | |
EMAILMESSAGE="email_password.txt" | |
SUBJECT="New password for email account" | |
LOGMSG="emaillog.txt" | |
echo > $LOGMSG | |
while read USERNAME | |
do | |
#PASSWORD=`ipa user-mod --random --raw ${USERNAME} | grep randompassword | awk '{print $2}'` | |
PASSWORD=`openssl rand -base64 6` | |
ipa passwd $USERNAME $PASSWORD | |
ipa user-disable $USERNAME | |
ipa user-enable $USERNAME | |
echo "Hi," > $EMAILMESSAGE | |
echo >> $EMAILMESSAGE | |
echo "In relation to the advisory we have released about e-mail migration, below is your new password: " >> $EMAILMESSAGE | |
echo >> $EMAILMESSAGE | |
echo " Username: ${USERNAME}" >> $EMAILMESSAGE | |
echo " Password: ${PASSWORD}" >> $EMAILMESSAGE | |
echo >> $EMAILMESSAGE | |
echo "To change and set your original password, please visit $URL >> $EMAILMESSAGE | |
echo >> $EMAILMESSAGE | |
echo "Best Regards" >> $EMAILMESSAGE | |
echo "SysAdmin Team" >> $EMAILMESSAGE | |
echo >> $LOGMSG | |
echo "Authentication information set for account ${USERNAME}" >> $LOGMSG | |
mail -s "$SUBJECT" -r $MAILFROM "[email protected]" < "$EMAILMESSAGE" | |
echo "Mail send to [email protected] " >> $LOGMSG | |
done < email_migrate_list.txt | |
mail -s "Password reset report" -r $MAILFROM $MAILFROM < $LOGMSG | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment