密码时效:脚本

密码时效:脚本

我们必须在我们的环境中实施密码时效。我知道使用chage和shadow文件很有可能。但由于我们的密码是由NIS处理的,所以我们不能使用chage方法来实现密码老化。我只是想知道我是否可以编写一个脚本来定期(每天)检查 passwd 文件,以便找出自 180 天以来所有用户都没有更改过密码,我收到了一封邮件通知。这样我就可以通知用户并要求他们更改密码。某种密码老化。我知道这不会是一个完美的案例,但我们必须采用这个解决方法。到目前为止,我们只有 55 个 UNIX 用户。由于我不喜欢编程,所以我请求大家为我提供一些关于如何做到这一点的提示。我已经尝试过,但不值得。

###Here the script will change the difference in two password files passwd.2 and passwd.11 and if there are differences then record them(only Usernames) in the file Table 
#!/bin/bash
#set -x


if [[ "$(diff passwd.2 passwd.11 )" != "" ]]; then
        ( date ; echo FileChanged ) >> Status2
        ( diff passwd.2 passwd.11 ) >> Status2
        diff --unchanged-line-format="" --old-line-format="" --new-line-format=":%dn: %L" passwd.2 passwd.11  |awk -F: '{print $3}' >> Table
        tail -15 Status2
        tail -15 Table
else
        ( date ; echo NOFileChanged ) >> Status2
fi

下面给出了一个示例密码文件。密码:

t1:$2y$05$lFZBPdAihnWxJPwfHeoI8WBdhzZGtcVJXXXXXXXXXXXXXXXXX:10954:20000:Test User temporary:/home/t1:/bin/bash
fdl:Nologin*:499:20190:fdl,Application User:/home/fdl:/bin/csh
v1:$2y$05$lPdAihnWXXXXXXXXXXXXXXXXXcPwfHeoI8WBdhzZGtcVJXXXXXXXXXXXXXXXXX:10955:20000:Test User temporary:/home/v1:/bin/bash
v2:$2y$05BPdAihnWxJeXXXXXXXXXXXXXXXXXoI8WBdhzZGXXXXXXXXXXXXXXXXX:10956:20000:Test User temporary:/home/v2:/bin/bash
v3:$2y$05$lFZBPdAiXXXXXXXXXXXXXXXXXoI8WBdhzZGXXXXXXXXXXXXXXXXX:10957:20000:Test User temporary:/home/v3:/bin/bash
v4:$2y$05$lFZBPdAXXXXXXXXXXXXXXXXXfHeoI8WBdhzXXXXXXXXXXXXXXXXX:10958:20000:Test User temporary:/home/v4:/bin/bash

相关内容