find密码不变的用户?

我最近添加了一堆用户,并给他们随机生成的密码。 我们已经指示他们更改密码,但是我们怀疑其中有很多人没有。

我们怎样才能过滤没有更改密码的人的密码呢?

我们在Ubuntu 9.04服务器上使用普通的/ etc / passwdauthentication。

您可以使用chage命令查看上次更改密码的时间,例如:

sudo chage -l kbrandt 

你可以把它和/ etc / passwd文件的一个循环和awk结合起来,可能是更好的办法。 也许是这样的:

 while read line; do date_change=$(echo $line | awk -F: '{print $3}') user=$(echo $line | awk -F: '{print $1}') #Say you set them on 14120 days since Jan 1, 1970 if [[ $date_change -eq 14120 ]]; then #chage command to set warning and password expiration for $user fi done < /etc/shadow 

要过期的密码将到期date设置为过去的date:

 chage -E 0 username # 0 is January 1, 1970; 14496 is 9/9/9 

要删除到期使用-1:

 chage -E -1 username 

将这些与凯尔的剧本结合起来。

但是 ,您date_change使用一次awk就可以获取userdate_change

 # Bash read user date_change <<< $(echo $line | awk -F: '{print $1, $3}') 

要么

 # Bash read user date_change < <(echo $line | awk -F: '{print $1, $3}') 

要么

 # Bourne read user date_change <<EOF `echo $line | awk -F: '{print $1, $3}'` EOF 

但是awk是不必要的:

 while IFS=: read -a line do date_change=${line[2]} user=${line[0]} # Have they changed their password since I told them to on Jul 1? if [[ $date_change <= 14426 ]]; then # Expire their password, that'll get their attention chage -E 0 $user fi done < /etc/shadow 

密码上次更改的date列在第三个字段的/ etc / shadow中(编码为1970/01/01以来的天数)。

您可以使用chage utiliy在上次更改后的n天之后执行密码更改。 但是要注意,这个设置是持久的,每隔n天就会过期一次,所以如果你不想在第一次更改之后第二次运行就重置。

我真的想要一个选项来执行第一次login时的密码更改,如MacOS和Windows提供。