RHEL should have a working getent
, so you can get the password age data from there. It's the third field, as a number of days from 1970. Today's day number can be found from the current time in seconds since the epoch divided by 86400 and truncated. (Well, give or take your time zone offset, maybe. I'm not sure if the shadow tools store the day number according to the local timezone, or according to UTC.)
# user=ilkkachu
# age=$(( $(date +%s) / 86400 - $(getent -- shadow "$user" |cut -d: -f3) ))
# printf "age of user %s's password is %d days\n" "$user" "$age"
age of user ilkkachu's password is 1444 days
You'll likely need to be root so that getent
can get the required information, though. (That would be true for data in /etc/shadow
, but if the data is in e.g. LDAP, it could depend on the configuration.)
Of course allowing someone to run getent
as root (e.g. via sudo) would also allow them to see the password hash, which they don't need, and which would be more than just chage -l
let them know. To prevent that, or at least make it harder, you could create a script that runs that getent | cut
pipeline and only allow them permission to run that.