The “chage” Command in Linux [7 Practical Examples]

LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now

The chage command has one of the most important uses in Linux. It is a very easy-to-use command that is used to change the user account’s password expiry information. In this article, you will get to know the syntax, options, and practical applications of the chage command in Linux.

A. Description

The chage command in Linux displays the user account’s aging information, changes the last password change date, and specifies the account expiration date, and minimum & maximum number of days between password change. It is also used to change the user account’s aging information.

B. Syntax

The chage command in Linux has a simple syntax. In the syntax, you need to mention the user whose accounts’s aging information you want to view or modify. And the syntax is as follows:

chage [-OPTION] [USER]

Note: In the syntax above, OPTION is enclosed by a square bracket denoting one option that can be used at the same time

C. Options

A large number of options are available for the chage command in Linux. You can see the most useful options of the command are listed here. However, you can look for the chage command on the man page to know more about its options.

man chage

Useful Options

  • -l, Displays account aging information.
  • -d, Changes last password change date.
  • -E, Specifies the account expiration date.
  • -I, Specifies the number of days of the account inactivity.
  • -m, Specifies the minimum number of days between password change.
  • -M, Specifies the maximum number of days between password change.
  • -W, Specifies the number of days of warning.
Note: The options in Linux CLI (Command Line Interface) are case-sensitive, so be cautious when you use them.

Practical Examples of the “chage” Command in Linux

The chage command in Linux is used to view & modify the user account’s aging information. You will learn some useful practical examples of the chage command in Linux here.

Example 1: Display Account Aging Information Using the “chage” Command in Linux

To display the aging information of the account I am using chage command in Linux along with option -l. I am also using the sudo command as I want to view the information of the root. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To display the account aging information, type the following command in the command prompt:

sudo chage -l root

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Finally, press the ENTER button.

Output >

In the image below, the output shows the aging information of the account.displays account aging information


Similar Readings


Example 2: Change Last Password Change Date to the Specified Date

To change the last password change date of the account you can use chage command in Linux along with option -d. You have to use the sudo command to have access in the root.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To change the last password change date, type the following command in the command prompt:

sudo chage -d 2022-12-01 root
Note: You can use any date of your choice here.

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Then, press the ENTER button.

❻ To check the last password change date, type the following command in the command prompt:

sudo chage -l root

❼ Finally, press the ENTER button.

Output >

In the following images, you can see the last password change date of the account is changed.

Before changing the last password change date Before changing the last password change dateAfter changing the last password change date changed the last password change date

Example 3: Specify the Account Expire Date Using “chage” Command in Linux

To specify the account expiration date you can use chage command in Linux along with option -E. You have to use the sudo command to have access in the root.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To specify the account expiration date, type the following command in the command prompt:

sudo chage -E 2080-10-05 root
Note: You can use any date of your choice here.

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Then, press the ENTER button.

❻ To check the account expiration date, type the following command in the command prompt:

sudo chage -l root

❼ Finally, press the ENTER button.

Output >

In the following images, you can see the account expiration date of the account is changed.

Before specifying the account expiration dateno account expire date before specifyingAfter specifying the account expiration datespecified the account expiration date


Similar Readings


Example 4: Specify the Minimum Number of Days Between Password Change

To specify the minimum number of days between password change of the account I am using chage command in Linux with option -m. I also have to use the sudo command to have access in the root. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To specify the minimum number of days to expire the password of the account, type the following command in the command prompt:

sudo chage -m 1 root

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Then, press the ENTER button.

❻ To check the account expiration date, type the following command in the command prompt:

sudo chage -l root

❼ Finally, press the ENTER button.

Output >

In the images below, you can see the minimum number of days between the password change of the account is changed.

Before specifying the minimum number of days between password changeBefore specifying the minimum number of days between password changeAfter specifying the minimum number of days between password changeAfter specifying the minimum number of days between password change

Example 5: Specify the Maximum Number of Days Between Password Change

To specify the maximum number of days between password change of the account I am using chage command in Linux with option -m. I am also using the sudo command to have access in the root. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To specify the maximum number of days to expire the password of the account, type the following command in the command prompt:

sudo chage -M 90000 root

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Then, press the ENTER button.

❻ To check the account expiration date, type the following command in the command prompt:

sudo chage -l root

❼ Finally, press the ENTER button.

Output >

In the following images, you can see the maximum number of days between the password change of the account is changed.

Before specifying the maximum number of days between password changeAfter specifying the maximum number of days between password changeAfter specifying the maximum number of days between password changeAfter specifying the maximum number of days between password change


Similar Readings


Example 6: Specify the Number of Days of Warning Using “chage” Command in Linux

To specify the number of days of warning before password change of the account I am using chage command in Linux along with option -W. I am also using the sudo command to have access in the root. To do the same you can follow the procedure below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To specify the number of days of warning before password change of the account, type the following command in the command prompt:

sudo chage -W 3 root

➌ Now, press the ENTER button.

❹ As it will ask for the password, type the password of the account in the command prompt.

➎ Then, press the ENTER button.

❻ To check the account expiration date, type the following command in the command prompt:

sudo chage -l root

❼ Finally, press the ENTER button.

Output >

In the images below, you can see the number of days of warning before the password expiration of the account is changed.

Before specifying the number of days before password expirationBefore specifying the number of days before password expirationAfter specifying the number of days before password expirationAfter specifying the number of days before password expiration


Similar Readings


Example 7: Change the Account Aging Information For the User Using “chage” Command in Linux

To change the account aging information for the user you can use chage command in Linux. You have to use the sudo command to have access in the root.

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ To specify the account aging information for the user, type the following command in the command prompt:

sudo chage sylvie

Note: Here sylvie is the user. You can use any user.

➌ Now, press the ENTER button.

❹ Type the new value in the command prompt.

➎ Then, press the ENTER button after typing each value.

❻ To check the changed information, type the following command in the command prompt:

sudo chage -l sylvie

❼ Finally, press the ENTER button.

Output >

As you can see, All the account aging information are changed.Change the Account Aging Information For the User

Conclusion

As you have seen in this article, the chage command has so many uses in user account in Linux. You’ve also learned the syntax, some functional options, and the practical application of this command. To become a master in Linux, try practical applications of this command by yourself.


Similar Readings

Rate this post
Jannatul Ferdousi Sylvie

Hi there! This is Jannatul Ferdousi Sylvie. I am one of the Linux Content Developer Executives at Softeko. I live in Dhaka, Bangladesh. I have completed my BSc. in Software Engineering from American International University-Bangladesh. You can see my projects in the GitHub account. I love traveling, shopping, cooking, and gardening. Read Full Bio

Leave a Comment