Linux system administrators often need to manage user accounts and their passwords. The chage command is a powerful tool that helps in managing user password expiry and aging information in Linux. In this article, we’ll guide you through the use of the chage command in Linux, its various options, and examples of how to use them effectively.
What is the Chage Command?
The chage command in Linux is used to change user password expiry information. It allows administrators to set password aging policies, ensuring that users change their passwords periodically for better security. The command is particularly useful when managing multiple users and enforcing password best practices.
Basic Syntax
The basic syntax of the chage command is:
1 | chage [options] [user] |
Where [options] are the command options, and [user] is the username for which you want to modify the password expiry settings.
Common Options
Here are some of the most commonly used options with the chage command:
-d
,--lastday
: Set the last password change date.-E
,--expiredate
: Set the account expiration date.-h
,--help
: Display help information.-I
,--inactive
: Set the number of inactive days after password expiry.-l
,--list
: List password and account information.-m
,--mindays
: Set the minimum number of days between password changes.-M
,--maxdays
: Set the maximum number of days before a password change is required.-W
,--warndays
: Set the number of days before the password expires to warn the user.
Examples of Using the Chage Command
- List password and account information:
To display the password and account information for a specific user, use the
-l
or--list
option.chage -l username
- Set the minimum number of days between password changes:
To enforce a minimum number of days between password changes for a user, use the
-m
or--mindays
option.chage -m 7 username
This command sets the minimum number of days between password changes to 7 for the specified user.
- Set the maximum number of days before a password change is required:
To set the maximum number of days a password can be used before it must be changed, use the
-M
or--maxdays
option.chage -M 90 username
This command sets the maximum number of days before a password change is required to 90 for the specified user.
- Set the number of days before the password expires to warn the user:
To notify a user about an impending password expiry, use the
-W
or--warndays
option.chage -W 7 username
This command sets a warning period of 7 days before the password expires for the specified user.
- Set the number of inactive days after password expiry:
To define a period of inactivity after the password expires, use the
-I
or--inactive
option.chage -I 14 username
This command sets the number of inactive days after password expiry to 14 for the specified user. After this period, the account will be locked.
- Set the last password change date:
To manually set the last password change date, use the
-d
or--lastday
option.chage -d 2023-04-01 username
This command sets the last password change date to April 1, 2023, for the specified user.
- Set the account expiration date:
To set an expiration date for a user account, use the
-E
or--expiredate
option.chage -E 2023-12-31 username
This command sets the account expiration date to December 31, 2023, for the specified user.
Conclusion
The chage command is an essential tool for Linux system administrators to manage password aging policies and user account expiration. By using this command, administrators can enforce password best practices and maintain a higher level of security for their systems. It’s important to understand the various options available with the chage command and use them effectively to manage user accounts.
Remember that the chage command requires root or sudo privileges to modify user account information. Therefore, always exercise caution when executing commands that modify system settings or user accounts. By following the examples provided in this article, you’ll be well-equipped to manage password aging and account expiration in your Linux environment.