@@ -191,24 +191,23 @@ conf_msg "Password updated"
191191# Expire passwords of all other users
192192short_msg " Expiring all user passwords except for user..."
193193
194- # Count the number of non-root users on the system
195- num_users =$( getent passwd | grep -v ' /bin/false ' | grep -v ' /sbin/nologin ' | wc -l )
196- current_user= $( whoami )
197-
198- # Check if there are other users besides the current user and root
199- if [ " $num_users " -gt 2 ] ; then
200- # Loop through all user accounts and exclude the current user and root
201- for username in $( getent passwd | cut -d: -f1 ) ; do
202- if [ " $username " != " $current_user " ] && [ " $username " != " root " ] ; then
203- echo " Expiring password for user: $ username"
204- chage -E 0 " $username "
205- fi
194+ # Get the UID of the current user
195+ current_user_uid =$( id -u )
196+
197+ # Count the number of non-root human users on the system
198+ num_users= $( getent passwd | awk -F: ' $3 >= 1000 && $3 != ' $current_user_uid ' {print $1} ' | wc -l )
199+
200+ # Check if there are other human users besides the current user
201+ if [ " $num_users " -gt 0 ] ; then
202+ # Loop through all user accounts and exclude the current user
203+ getent passwd | awk -F: ' $3 >= 1000 && $3 != ' $current_user_uid ' {print $1} ' | while read -r username; do
204+ short_msg " Expiring password for user: $username "
205+ chage -E 0 " $username "
206206 done
207207 space_1
208- short_msg " ${bold} All other users' passwords have now expired${normal} . "
208+ short_msg " ${bold} Passwords for other human users have now expired. ${normal} "
209209 short_msg " They will be prompted to update their password on the next login."
210210 sleep 1
211-
212211fi
213212
214213space_2
0 commit comments