Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check the expiration time of a user's account in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

If you enable password policy on Linux. The password must be changed before expiration and will be notified when logging in to the system. If you rarely use your own account, you may be locked out because your password has expired. In many cases, this may happen in a service account that does not require a password login because no one will notice it.

This will cause the cronjob/crontab configured on the server to be stopped. If so, how to alleviate the situation. You can write a shell script to get notification about it, and we wrote an article about it some time ago. "use the Bash script to send an email with a list of user accounts that expire within a few days." it will give the number of days, but this article is intended to give you the actual date in the terminal. This can be done using the chage command.

What is the chage command?

Chage stands for change aging change age. It changes the user's password expiration information.

The chage command modifies the number of days between two password changes, as well as the date when the password was last changed.

The system uses this information to determine when the user should change the password.

It also allows users to perform other functions, such as setting account expiration dates, setting passwords to invalid after expiration, displaying account expiration information, setting the minimum and maximum number of days before password changes, and setting expiration warning days.

1) how to check the password expiration date of a specific user on Linux

If you want to check the password expiration date for a specific user on Linux, use the following command.

# chage-l daygeek Last password change: Feb 13, 2020Password expires: May 13 2020Password inactive: neverAccount expires: neverMinimum number of days between password change: 7Maximum number of days between password change: 90Number of days of warning before password expires: 72) how to check the password expiration date of all users on Linux

You can use the chage command directly for a single user, but it may not work for multiple users.

To do this, you need to write a small shell script. The following shell script lists all users added to the system, including system users.

# 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 output similar to the following, but the user name may be different.

Root: neverbin: neverdaemon: neveradm: neverlp: neversync: nevershutdown: neveru1: Nov 12, 2018u2: Jun 17, 2019u3: Jun 17, 2019u4: Jun 17, 2019u5: Jun 17 20193) how to check the password validity of all users except system users on Linux

The following shell script displays a list of users with an expiration date.

# 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 output similar to the following, but the user name may be different.

U1: Nov 12, 2018u2: Jun 17, 2019u3: Jun 17, 2019u4: Jun 17, 2019u5: Jun 17, 2019

Original address: https://www.linuxprobe.com/linux-check-user-account.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report