Linux, コマンド · 2 min read · Feb 02, 2026

Linux chage コマンド入門 (6つの例)

Linux コマンドラインはユーザー管理のためのいくつかのツールを提供しています(そのいくつかについてはすでに説明しました)。そのようなユーティリティの一つが chage で、パスワードの有効期限情報を調整することができます。このチュートリアルでは、いくつかのわかりやすい例を使ってこのツールについて説明します。しかし、始める前に、ここでのすべての例は Ubuntu 18.04 LTS マシンでテストされていることを述べておく価値があります。

Linux chage コマンド

chage コマンドは、上記で説明したように、ユーザーのパスワードの有効期限情報を調整することができます。以下がその構文です:

chage [options] LOGIN

そして、man ページには次のように記載されています:

       The chage command changes the number of days between password changes  
       and the date of the last password change. This information is used by  
       the system to determine when a user must change his/her password.

以下は、chage コマンドがどのように機能するかを理解するのに役立つ Q&A スタイルの例です:

Q1. 現在のパスワードの有効期限情報を表示するには?

ユーザーの現在のパスワードの有効期限日情報を表示するには、-l コマンドラインオプションを使用します。

chage -l [USERNAME]

以下は例です:

chage -l himanshu

そして、私のシステムで生成された出力は以下の通りです:

Last password change                       : Jul 26, 2018  
Password expires                           : never  
Password inactive                          : never  
Account expires                            : never  
Minimum number of days between password change   : 0  
Maximum number of days between password change   : 99999  
Number of days of warning before password expires   : 7

現在、パスワードは「決して期限切れにならない」と設定されています。

Q2. パスワードの有効期限日を変更するには?

これは、-M コマンドラインオプションを使用して行うことができ、数値(パスワードが有効な最大日数を指します)を渡す必要があります。

例えば:

chage -M 1000 himanshu

この操作にはルート権限が必要です。

上記のスクリーンショットで見ると、パスワードの有効期限が 2021 年 4 月 21 日に設定されたことがわかります。

また、パスワード変更の間の最小日数を設定するために使用される -m コマンドラインオプションも使用できます。上記で説明した -M オプションは、パスワードが有効な最大日数を設定します。

Q3. 最後のパスワード変更日を変更するには?

-d コマンドラインオプションを使用して最後のパスワード変更日を調整できます。入力として、このオプションに数値を渡すか、完全な日付を渡すことができます。man ページでは次のように説明されています:

 -d, --lastday LAST_DAY  
           Set the number of days since January 1st, 1970 when the password  
           was last changed. The date may also be expressed in the format  
           YYYY-MM-DD (or the format more commonly used in your area).

以下は例です:

「最後のパスワード変更」フィールドの値が正常に変更されたことがわかります。

Q4. パスワードの有効期限前にユーザーに警告するには?

chage コマンドは、パスワード変更が必要になる前の警告日数を設定することもできます。これは -W コマンドラインオプションを使用して行うことができます。

-W, --warndays WARN_DAYS  
           Set the number of days of warning before a password change is  
           required. The WARN_DAYS option is the number of days prior to the  
           password expiring that a user will be warned his/her password is  
           about to expire.

例えば:

chage -W 10 himanshu

このコマンドは、ユーザーがパスワードが期限切れになる 10 日前に警告を受け取ることを保証します。

Q5. アカウントをロックするには?

アカウントをロックするには -E コマンドラインオプションを使用します。入力の受け取り方は、上記で説明した -W オプションと似ています。参考のために、man ページでは次のように説明されています:

-E, --expiredate EXPIRE_DATE  
           Set the date or number of days since January 1, 1970 on which the  
           user's account will no longer be accessible. The date may also be  
           expressed in the format YYYY-MM-DD (or the format more commonly  
           used in your area). A user whose account is locked must contact the  
           system administrator before being able to use the system again.  
           
           Passing the number -1 as the EXPIRE_DATE will remove an account  
           expiration date.

例えば:

chage -E 2019-06-21 himanshu

このコマンドは、ユーザー「himanshu」のアカウントが 2019 年 6 月 21 日からアクセスできなくなることを保証します。

Q6. chage がオプションなしで使用された場合はどうなりますか?

この場合、次のようになります:

       If none of the options are selected, chage operates in an interactive  
       fashion, prompting the user with the current values for all of the  
       fields. Enter the new value to change the field, or leave the line  
       blank to use the current value. The current value is displayed between  
       a pair of [ ] marks.

chage がオプションなしで使用された場合の結果

結論

Linux システム管理者や、Linux マシンのユーザー管理を担当している人にとって、このコマンドは覚えておく価値があります。ここでは、いくつかの chage コマンドラインオプションをカバーしました。詳細を学ぶには、chage man ページにアクセスしてください。

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。