Is there a way with either commands passwd or chage to force the password to expire 90 days from the time of command execution?I know I can do it by date, such as:chage -E 2014-07-31 useridBut I'm looking for a way to do it by with a number instead of a specific date.Thank you!
Resetting password expiry date by number of days instead of specifying date
linux;password;passwd
chage doesn't handle date differences by itself, but you can let the shell take care of that and give chage a number of days since 1970-01-01 instead of a YYYY-MM-DD date representation:chage -E $(( $(date +%s)/3600/24 + 90 )) userid(Replace 90 with any number of days.)Changing the expiration date of the password rather than the account is a little trickier  in fact, you cannot set an actual expiration date for the password, just a maximum age (using chage -M).To compute the maximum age required for the password to expire 90 days from now, we need to jump through a few more hoops:userid=johndoepwd_age=$(grep ^$userid: /etc/shadow | cut -d: -f 3)now=$(( $(date +%s) / 3600 / 24 ))age_at_expiry_date=$(( $now + 90 - $pwd_age ))chage $userid -M $age_at_expiry_dateIf you don't mind it being rather convoluted, you can even combine that into a one-liner:userid=johndoe chage $userid -M $(( $(date +%s) / 3600 / 24 + 90 - $(grep ^$userid: /etc/shadow | cut -d: -f 3) ))If you don't mind overwriting the date when the password was last changed, you can justchage -M 90 -d $(date +%F) userid