How To Show Linux User Password Expires
Tags: Expire, Linux, Password, username
In order to show password expires for any particular username on Linux, I use chage command. For an example:
#chage -l test
Minimum: 0
Maximum: 76
Warning: 14
Inactive: 7
Last Change: Jul 29, 2008
Password Expires: Oct 13, 2008
Password Inactive: Oct 27, 2008
Account Expires: Never
So, as you can see from the screen above, the Linux system show username: test password expires on Oct 13, 2008. Basically the ‘Password Expires’ calculation is ‘Last Change’ date + ‘Maximum’ of day on the system.
Again, if you would like to check more than one user, probably you can try some of the example as below:
Option 1:
for i in `cat /etc/passwd | awk -F: ‘{print $1}’`; do echo “UserName:${i}”; chage -l $i|grep “Password Expires” ;done
Output:
UserName:lilya
Password Expires: Aug 18, 2008
UserName:liuma
Password Expires: Sep 23, 2008
UserName:racq
Password Expires: Never
UserName:podbct
Password Expires: Never
UserName:podad
Password Expires: Never
UserName:test
Password Expires: Aug 16, 2008
UserName:limsq
Password Expires: Sep 23, 2008
Option 2:
for i in `cat /etc/passwd | awk -F: ‘{print $1}’`; do echo -n “UserName:${i}” ” => “; chage -l $i|grep “Password Expires” ;done
Output:
UserName:kellyp => Password Expires: Never
UserName:johnc => Password Expires: Dec 07, 2008
UserName:lilya => Password Expires: Aug 18, 2008
UserName:liume => Password Expires: Sep 23, 2008
Option 3:
Create a new script and paste the following content into your script. If you would like to check userID larger than 500 then you should change from 1000 to 1000.
#!/bin/sh
while read inputline
do
NAME=”$(echo $inputline | cut -d: -f1)”
ID=”$(echo $inputline | cut -d: -f3)”
if [ $ID -ge 1000 ]; then
echo -n “User: ” $NAME ” => ” ; chage -l $NAME | grep “Password Expires”
fi
done < /etc/passwd
Done!
Possibly Related Posts:
- RSS Feed Submissions
- Geo Positions
- Interesting about Google Suggest
- Setup a Linux Highly Availability NFS servers
- How to find empty folders on Linux
