Let me preface this with: I do NOT have root access available.

I recently got locked out of my account because I did not know the password expiration was getting close, then elapsed. I want to add a check to my startup script that checks and displays the time so I know when it is coming near.

Is there a command or way of getting the timestamp when my user password will expire?


You should be able to get that information from the chage utility. Doesn't require root to run in list mode.

Note: this most likely only works for local, passwd-based authentication. I don't know if it can be made to work with authentication modes that don't put login information in the passwd/shadow files. I'm guessing these solutions provide their own tools, but don't know about them.

$ chage -l test                       
Last password change                                : Apr 17, 2012
Password expires                                    : Apr 27, 2012
Password inactive                                   : never
Account expires                                     : May 20, 2012
Minimum number of days between password change      : 0
Maximum number of days between password change      : 10
Number of days of warning before password expires   : 7

I've used that with a quick awk to display my password expiration date on login.

| improve this answer | |
  • Odd, I get an error: unknown user. I even tried whoami | xargs chage -l to make sure I wasn't doing something obviously wrong. – steveo225 Apr 17 '12 at 19:09
  • What does whoami return, and what does grep $(whoami) /etc/password do? – Mat Apr 17 '12 at 19:23
  • This appears to only work if the user is local (not in LDAP or other database). – Patrick Apr 18 '12 at 0:29
  • @Patrick: you're most likely right, and I don't have access to machines with that type of authentication setup. So can't provide additional info. – Mat Apr 18 '12 at 11:25
  • whoami does return my proper username, but I do believe the system is using LDAP. – steveo225 Apr 18 '12 at 11:54

In ldap you will do something like:

ldapsearch -x -Z  uid=$1 pwdChangedTime | \
          grep -vE '^#|^$' | grep pwdChangedTime | awk '{print $2}'
| improve this answer | |

From chage you can do multiple changes and can know the login details as follows...

Usage: chage [options] [LOGIN]

  -d, --lastday LAST_DAY        set date of last password change to LAST_DAY
  -E, --expiredate EXPIRE_DATE  set account expiration date to EXPIRE_DATE
  -h, --help                    display this help message and exit
  -I, --inactive INACTIVE       set password inactive after expiration
                                to INACTIVE
  -l, --list                    show account aging information
  -m, --mindays MIN_DAYS        set minimum number of days before password
                                change to MIN_DAYS
  -M, --maxdays MAX_DAYS        set maximim number of days before password
                                change to MAX_DAYS
  -W, --warndays WARN_DAYS      set expiration warning days to WARN_DAYS

and if you have Root access then can change your password expire time just edit ..

vim /etc/login.defs

just setup the vlaues below...


It may help you

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.