我觉得问这个问题有点傻,但是:在 Solaris 中,您可以发出一个passwd -sa
命令,它给您(或多或少)相同的输出passwd -S userName
,除了它打印出在 /etc/passwd 中找到的所有用户的状态信息。等效的 GNU/Linux 命令是什么?
我正在尝试为其他人整理简单的说明来设置服务器基线,其中一部分是他们识别所有帐户上配置的密码时效。我可以 for 循环,cut -f1 -d: /etc/passwd
但我希望我可以给他一个简单的命令。
答案1
在 RHEL/CentOS 中,没有-a
passwd 选项,但-S
有选项。因此,您以 root 用户身份运行这一行:
for user in `awk -F: '{print $1}' /etc/passwd`; do passwd -S $user; done
或者
for user in $(awk -F: '{print $1}' /etc/passwd); do passwd -S $user; done
答案2
至少在 Arch Linux 上的 Shadow-utils 4.1.5.1 中,我有-a
,它也会打印状态。passwd -Sa
似乎做你想做的事。从man passwd
:
-a, --all
This option can be used only with -S and causes show status for all users.
-S, --status
Display account status information. The status information consists
of 7 fields. The first field is the user's login name. The second
field indicates if the user account has a locked password (L), has
no password (NP), or has a usable password (P). The third field
gives the date of the last password change. The next four fields
are the minimum age, maximum age, warning period, and inactivity
period for the password. These ages are expressed in days.
# passwd -Sa
root P 05/07/2013 -1 -1 -1 -1
bin P 09/19/2010 -1 -1 -1 -1
daemon P 09/19/2010 -1 -1 -1 -1
mail P 09/19/2010 -1 -1 -1 -1
ftp P 09/19/2010 -1 -1 -1 -1
http P 09/19/2010 -1 -1 -1 -1
uuidd P 09/19/2010 -1 -1 -1 -1
dbus P 09/19/2010 -1 -1 -1 -1
nobody P 09/19/2010 -1 -1 -1 -1
git L 05/07/2013 -1 -1 -1 -1
chris P 05/07/2013 0 99999 7 -1
avahi L 05/07/2013 -1 -1 -1 -1
mpd L 05/07/2013 -1 -1 -1 -1
ntp L 05/07/2013 0 99999 7 -1
nullmail L 05/13/2013 -1 -1 -1 -1
polkitd L 05/14/2013 0 99999 7 -1