Using Command "Chage" for Everyone in the Group Group

How can i use "chage" command to change, for example, minimum number of days before password change for every user in the group?

1 Answer

I don't think there's a one-shot command to do this, so you would need to extract the list of members from the groups database and loop over it - exactly how you choose to do that is up to you but for example

#!/bin/bash

group='group'
mindays=28

IFS=, read -a members < <(getent group "$group" | cut -d: -f4)

for logname in "${members[@]}"; do
  echo chage -m "$mindays" "$logname"
done

(remove the echo once you are satisfied that it will do the right thing).

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest