Open In App

chage command in Linux with examples

Last Updated : 13 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The ‘chage’ command in Linux is a powerful tool used to manage user password expiry and account aging information. It is particularly useful in environments where user access needs to be controlled over time, such as when login access is time-bound or when it’s necessary to enforce regular password changes for security purposes. With the ‘chage’ command, administrators can view and modify password expiry details, set mandatory password change intervals, specify account expiration dates, and more.

Here we will walk you through the syntax, options, and practical examples of the ‘chagecommand.

What is the ‘chage’ command?

The ‘chage’ command, short for “change age,” allows system administrators to manage account aging parameters, including when a password was last changed, when it must be changed next, and when an account should be locked or warned about password expiration. This command is essential for maintaining security policies that require users to update their passwords periodically or limit the duration of user access.

Syntax:

chage [options] LOGIN

where,

  • ‘[options]’: Flags that modify the behavior of the command.
  • LOGIN‘: The username of the account you want to modify.

In order to view the list of options that can be used with the chage command, use the help option:

chage -h 

Output:

Common Options and Examples of ‘chage’ command  in Linux

1. ‘-l’ option (List Account Aging Information)

Use this option to view the account aging information. In order to view the aging information of the root, use the keyword ‘sudo‘.

Input : sudo chage -l root

Output:

2. ‘-d’ option (Set Last Password Change Date)

Use this option to set the last password change date to your specified date in the command. In order to change the aging information of the root, use the keyword “sudo“. Further using the ‘-l’ option to view the changed date.

Input : sudo chage -d 2018-12-01 root

Output :

 

3. ‘-E’ option (Set Account Expiry Date)

Use this option to specify the date when the account should expire. In order to change the aging information of the root, use the keyword sudo. Further using the ‘-l’ option to view the changed date.

Input : sudo chage -E root

Output:

4. ‘-M’ and ‘-m’ option (Set Maximum and Minimum Password Age)

Use this option to specify the maximum and minimum number of days between password change. In order to change the aging information of the root, use the keyword ‘sudo’. Further using the ‘-l’ option to view the changed period.

Input : sudo chage -M 5 root

Output:

 

5. ‘-I’ option (Set Inactivity Period After Password Expiry)

Use this option to specify the number of days the account should be inactive after its expiry. It is necessary that the user should change the password after it expires, this command is useful when the user does not login after its expiry. Even after this inactivity period if the password is not changed then the account is locked and the user should approach the admin to unlock it.

In order to change the aging information of the root, use the keyword ‘sudo’. Further we used the ‘-l’ option to view the inactivity period.

Input : sudo chage -I 5 root

Output: 

6. ‘-W’ option (Set Password Expiry Warning)

Use this option to give prior warning before the password expires.The input given in the command is the number of days prior to the expiry date when the warning should be given. In order to change the aging information of the root, use the keyword ‘sudo’. Further, using the ‘-l’ option to view the warning period.

Input : sudo chage -W 2 root

Output: 

Conclusion

The ‘chage’ command is a versatile and essential tool for Linux administrators tasked with managing user accounts and enforcing password policies. By understanding and utilizing the full range of options available with ‘chage’, administrators can effectively control access duration, enforce password changes, and maintain a secure environment.


Next Article
Article Tags :

Similar Reads