lchage Command in Linux



The lchage command in Linux is used to manage user password policies. This command allows users to set and modify various aspects of password management, such as the last password change date, password inactivity periods, and account expiration. With lchage, you can also define the minimum and maximum number of days between password changes and set warning days before password expiration. This command is useful for enforcing security policies and ensuring that user accounts are properly managed and secure.

Table of Contents

Here is a comprehensive guide to the options available with the lchage command −

Installation lchage Command

To use the lchage command, you need to install the libuser package on Linux from your distribution’s package manager.

For Debian-based systems like Ubuntu, run

sudo apt install libuser

For Red Hat-based systems like CentOS or Fedora, run

sudo yum install libuser

For Arch Linux, use

sudo pacman -S libuser

For openSUSE, use

sudo zypper install libuser

Syntax of lchage Command

The syntax for the lchage command is −

lchage [options] user

Where −

  • [options] can include various flags to modify the command’s behaviour.
  • user is the username of the account you want to modify.

lchage Command Options

Option Description
-d, --date=DAYS Configures the days elapsed since January 1, 1970, when the password was last updated.
-E, --expire=DAYS Sets the number of days until the account expires.
-i, --interactive Prompts the user for input interactively.
-l, --list Displays account aging information.
-m, --mindays=DAYS Configures the least number of days required between password updates.
-M, --maxdays=DAYS Specifies the upper limit on the number of days a password remains valid.
-I, --inactive=DAYS Defines the period after which an expired password results in the account being disabled.
--usage Shows a usage message and then terminates the process.
-W, --warndays=DAYS Establishes the advance notification period before a password expires.

Examples of lchage Command in Linux

The following are some practical examples of the lchage command on a Linux system −

1. List Account Aging Information

To display account aging information for a user, you can use the -l option followed by the username. This will show details such as the last password change date, account expiration date, and more. For example, if you want to list the account aging information for the user ubuntu, execute the below-given command −

sudo lchage -l ubuntu
List Account Aging Information

2. Set Minimum Number of Days Between Password Changes

In case you want to set the minimum number of days between password changes, simply use the -m option followed by the number of days and the username. For example, to set a minimum of 7 days between password changes for the user ubuntu, run the below command −

sudo lchage -m 7 ubuntu

3. Set Maximum Number of Days the Password is Valid

To set the maximum number of days a password is valid, use the -M option followed by the number of days and the username. For example, to set a maximum of 90 days for the user ubuntu, use the command −

sudo lchage -M 90 ubuntu

4. Set Account Expiration Date

You can set the account expiration date using the -E option followed by the number of days since January 1, 1970, and the username. For example, to set the account of the user ubuntu to expire in 365 days, use the command −

sudo lchage -E 365 ubuntu

5. Set Warning Days Before Password Expiration

To set the number of days of warning before a password expires, use the -W option followed by the number of days and the username. For example, to set a warning 7 days before the password expires for the user ubuntu, use the command −

sudo lchage -W 7 ubuntu

Conclusion

The lchage command is a crucial tool for system administrators to manage user password policies on Linux systems. This tutorial has outlined the basic syntax, various options, and practical examples of using the lchage command.

Whether you need to set password expiration dates, define inactivity periods, or configure warning days, lchage offers a comprehensive and efficient way to enforce security policies and ensure that user accounts are properly managed and secure.

Advertisements