translated

This commit is contained in:
geekpi 2020-03-26 08:25:36 +08:00
parent 6d70c05ffd
commit ac03da8463

View File

@ -7,44 +7,44 @@
[#]: via: (https://www.2daygeek.com/linux-check-user-password-expiration-date/)
[#]: author: (Magesh Maruthamuthu https://www.2daygeek.com/author/magesh/)
How to Check Password Expiration Date for All Users on Linux
如何在 Linux 上检查所有用户密码到期日期
======
If you enable a **[password policy on Linux][1]**.
如果你在 **[Linux 上启用了密码策略][1]**。
The password must be changed before it expires, and you will be notified when you log in to the system.
密码必须在到期前进行更改,并且登录到系统时会收到通知。
If you rarely use your account, it may be locked due to password expiration.
如果你很少使用自己的帐户,那么可能由于密码过期而被锁定。
In many cases, this can happen in service accounts with a **[password-less login][2]**, because nobody will monitor it.
在许多情况下,这可能会在[无需密码登录][2]的服务帐户中发生,因为没人会注意到它。
This will lead to stop the **[cronjobs/crontab][3]** configured on the server.
这将导致停止服务器上配置的 **[cronjob/crontab][3]**。
If so, how to mitigate this situation.
如果如此,该如何缓解这种情况。
You can write a **[shell script][4]** to get a notification about it, for which we wrote an article some time ago.
你可以写一个 **[shell 脚本][4]**来获得有关它的通知,我们前一段时间为此写了一篇文章。
* **[Bash Script to Send eMail With a List of User Accounts Expiring in “X” Days][5]**
* **[发送 “X” 日内到期的用户帐户列表邮件的 Bash 脚本][5]**
This will give you the number of days, but this article aims to give you a actual date on your terminal.
它将给出天数,但是本文旨在在终端中给你实际日期。
This can be achieved with the chage command.
这可以使用 chage 命令来实现。
### What is chage Command?
### 什么是 chage 命令?
chage stands for change age. It changes user password expiration information.
chage 代表更改时效 change age。它更改用户密码到期信息。
The chage command changes the number of days between password changes and the date of the last password change.
chage 命令更改两次密码更改之间的天数,以及最后一次更改密码的日期。
This information is used by the system to determine when a user should change his/her password.
系统使用此信息来确定用户何时应更改密码。
It allows the user to perform other functions such as setting the account expiration date, setting the password inactive after the expiration, displaying account aging information, setting minimum and maximum days before password change, and setting expiry warning days.
它允许用户执行其他功能,例如设置帐户到期日期、在到期后将密码设置为无效、显示帐户时效信息、设置密码更改之前的最小和最大天数以及设置到期警告天数。
### 1) How to Check the Password Expiration Date for a Specific User on Linux
### 1)如何在 Linux 上检查特定用户的密码到期日期
If you want to check the password expiration date for a specific user on Linux, use the following command.
如果要检查 Linux 上特定用户的密码到期日期,请使用以下命令。
```
# chage -l daygeek
@ -58,17 +58,18 @@ Maximum number of days between password change : 90
Number of days of warning before password expires : 7
```
### 2) How To Check Password Expiration Date For All Users On Linux
### 2)如何在 Linux 上检查所有用户的密码到期日期
You can use the chage command directly for a single user, which may not work as expected for many users, but you can use it.
你可以直接对单个用户使用 chage 命令,这对你可以使用的多个用户可能无效。
To achieve this you need to write a small shell script. The shell script below allows you to list all users added to your system, including system users.
为此,你需要编写一个小的 shell 脚本。下面的 shell 脚本可以列出添加到系统中的所有用户,包括系统用户。
```
# for user in $(cat /etc/passwd |cut -d: -f1); do echo $user; chage -l $user | grep "Password expires"; done | paste -d " " - - | sed 's/Password expires//g'
```
You will get an output like the one below, but the username may differ.
你将得到类似以下的输出,但是用户名可能不同。
```
root : never
@ -85,15 +86,15 @@ u4 : Jun 17, 2019
u5 : Jun 17, 2019
```
### 3) How To Check Password Expiration Date For All Users Except System Users On Linux
### 3)如何检查 Linux 上除系统用户外的所有用户的密码有效期
The below shell script will display a list of users who has an expiry date.
下面的 shell 脚本将显示有到期日期的用户列表。
```
# for user in $(cat /etc/passwd |cut -d: -f1); do echo $user; chage -l $user | grep "Password expires"; done | paste -d " " - - | sed 's/Password expires//g' | grep -v "never"
```
You will get an output like the one below, but the username may differ.
你将得到类似以下的输出,但是用户名可能不同。
```
u1 : Nov 12, 2018
@ -109,7 +110,7 @@ via: https://www.2daygeek.com/linux-check-user-password-expiration-date/
作者:[Magesh Maruthamuthu][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出