How to reset multiple users password on Linux

Tags: , , , , ,
advertisement

How to reset multiple users password on Linux?

Choose a new password using perl with crypt format
#perl -e ‘print crypt(”newpassword”, “salt”),”\n”‘
sal.HhR9nxBk6

Reset password for any userID larger than 499 with new default password “newpassword”
#for acc in $(awk -F: ‘{ if ($3 > 499) { print $1 }}’ /etc/passwd); do
usermod -p sal.HhR9nxBk6 $acc;
done

Reset password for any userID larger than 499 but not userID=1150 & 1160 with new default password “newpassword”
#for acc in $(awk -F: ‘{ if ($3 > 499 && $3 !=1150 && $3 !=1160) { print $1 }}’ /etc/passwd); do
usermod -p sal.HhR9nxBk6 $acc;
done

Reset Samba password for any userID larger than 499 with new default password “newpassword”
#for acc in $(awk -F: ‘{ if ($3 > 499) { print $1 }}’ /etc/passwd); do
(echo ‘newpassword’; echo ‘newpassword’)|smbpasswd -s $acc;
done

Reset Samba password for any userID larger than 499 but not userID=1150 & 1160 with new default password “newpassword”
#for acc in $(awk -F: ‘{ if ($3 > 499 && $3 !=1150 && $3 !=1160) { print $1 }}’ /etc/passwd); do
(echo ‘newpassword’; echo ‘newpassword’)|smbpasswd -s $acc;
done

How to change user password expiry information
#for acc in $(awk -F: ‘{ if ($3 > 999) { print $1 }}’ /etc/passwd); do chage -m 7 -M 76 -W 14 -I 14 $acc; done

Quick check on one of the user
#chage -l test
Minimum: 0
Maximum: 76
Warning: 14
Inactive: 14
Last Change: Jul 01, 2008
Password Expires: Sep 15, 2008
Password Inactive: Sep 29, 2008
Account Expires: Never

Minimum = minimum number of days between password changes is changed
Maximum = maximum number of days during which a password is valid is changed
Warning = the number of days of warning before a password change is required can be changed
Inactive = used to set the number of days of inactivity after a password has expired before the account is locked

Enjoy!

If you are looking for how to sync Linux and Samba password, please check my previous post: How to SYNC Linux and Samba user password.

Possibly Related Posts:


Leave a Reply