<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Last password change date in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5306997#M53104</link>
    <description>&lt;P&gt;In newer Linux distributions, you don't need a script: a single command can do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;passwd -S -a&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;On each line, 1st field is the username, 2nd tells if the account is locked or not: L = locked, P = usable password, NP = no password (note: some modern Linux distributions won't allow logins to accounts that have no password, so NP may be effectively same as L). 3rd filed is the last password change date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the passwd command in your Linux distribution (what is its name?) does not support the -a option, you need to run "passwd -S &amp;lt;username&amp;gt;" separately for each user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For that, you first need a list of users. That is available to you in /etc/passwd. It contains colon-separated fields, and you only need the usernames in the first field of each line. So:&lt;/P&gt;&lt;PRE&gt;cut -d : -f 1 &amp;lt;/etc/passwd&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;will give you a list of users.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could save the list to a file, use a text editor to add "passwd -S " to the beginning of each line, save the result, and run it as a script. That works, but must be done again if the list of users changes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fortunately, there is a command that can take a list of things and make a series of commands out of it: the command is called "xargs".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can pipe the list of users to xargs, and tell it to run a series of commands, inserting one item from the list in place of {} each time, and give it a command template "passwd -S {}":&lt;/P&gt;&lt;PRE&gt;cut -d : -f 1 &amp;lt;/etc/passwd | xargs -I{} passwd -S {}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are certainly many other ways to solve your problem, but learning "cut" and "xargs" will help you to solve other similar problems in the future.&lt;/P&gt;</description>
    <pubDate>Sun, 21 Aug 2011 17:00:54 GMT</pubDate>
    <dc:creator>Matti_Kurkela</dc:creator>
    <dc:date>2011-08-21T17:00:54Z</dc:date>
    <item>
      <title>Last password change date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5306265#M53102</link>
      <description>&lt;P&gt;Hi Gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please share the script to check last password change date for all user in the system.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2011 18:06:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5306265#M53102</guid>
      <dc:creator>Arunabha Banerjee</dc:creator>
      <dc:date>2011-08-19T18:06:42Z</dc:date>
    </item>
    <item>
      <title>Re: Last password change date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5306997#M53104</link>
      <description>&lt;P&gt;In newer Linux distributions, you don't need a script: a single command can do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;passwd -S -a&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;On each line, 1st field is the username, 2nd tells if the account is locked or not: L = locked, P = usable password, NP = no password (note: some modern Linux distributions won't allow logins to accounts that have no password, so NP may be effectively same as L). 3rd filed is the last password change date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the passwd command in your Linux distribution (what is its name?) does not support the -a option, you need to run "passwd -S &amp;lt;username&amp;gt;" separately for each user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For that, you first need a list of users. That is available to you in /etc/passwd. It contains colon-separated fields, and you only need the usernames in the first field of each line. So:&lt;/P&gt;&lt;PRE&gt;cut -d : -f 1 &amp;lt;/etc/passwd&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;will give you a list of users.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could save the list to a file, use a text editor to add "passwd -S " to the beginning of each line, save the result, and run it as a script. That works, but must be done again if the list of users changes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Fortunately, there is a command that can take a list of things and make a series of commands out of it: the command is called "xargs".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can pipe the list of users to xargs, and tell it to run a series of commands, inserting one item from the list in place of {} each time, and give it a command template "passwd -S {}":&lt;/P&gt;&lt;PRE&gt;cut -d : -f 1 &amp;lt;/etc/passwd | xargs -I{} passwd -S {}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are certainly many other ways to solve your problem, but learning "cut" and "xargs" will help you to solve other similar problems in the future.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Aug 2011 17:00:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5306997#M53104</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2011-08-21T17:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Last password change date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5308527#M53108</link>
      <description>&lt;P&gt;It's giving following output. But I want exact date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;﻿﻿&lt;/P&gt;&lt;PRE&gt;[root@server1 ~]# passwd -S root
Password set, DES crypt.

[root@server1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux ES release 4 (Nahant Update 9)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2011 19:55:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5308527#M53108</guid>
      <dc:creator>Arunabha Banerjee</dc:creator>
      <dc:date>2011-08-22T19:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Last password change date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5309481#M53109</link>
      <description>&lt;P&gt;Looks like the "passwd -S &amp;lt;username&amp;gt;" does not display the password change date in RHEL 4. (It works on RHEL 5 and newer.) You can use "chage -l &amp;lt;username&amp;gt;" instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is, "chage -l" does not output the username at all, and it outputs multiple lines about the user.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you'll have to do this a bit differently, e.g. using a "while loop" which makes it easier to execute multiple commands for each username in the list:&lt;/P&gt;&lt;PRE&gt;#!/bin/sh
cut -d : -f 1 &amp;lt;/etc/passwd | while read USER
do
    echo "Username: $USER"
    chage -l "$USER" | grep "^Last Change"
    echo
done&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This script is tested on RHEL 4 Update 8.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2011 11:30:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5309481#M53109</guid>
      <dc:creator>Matti_Kurkela</dc:creator>
      <dc:date>2011-08-23T11:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: Last password change date</title>
      <link>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5309899#M53111</link>
      <description>&lt;P&gt;It works perfectly on RHEL 4.9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;have some older version of Linux (Red hat 7 / Red Hat 9/ RHEL3). So I will check and update.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2011 16:23:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/last-password-change-date/m-p/5309899#M53111</guid>
      <dc:creator>Arunabha Banerjee</dc:creator>
      <dc:date>2011-08-23T16:23:50Z</dc:date>
    </item>
  </channel>
</rss>

