{"id":6232,"date":"2018-08-15T16:18:34","date_gmt":"2018-08-15T12:18:34","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-chage-command\/"},"modified":"2018-08-15T16:18:34","modified_gmt":"2018-08-15T12:18:34","slug":"linux-chage-command-tutorial-for-beginners-6-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-chage-command-tutorial-for-beginners-6-examples\/","title":{"rendered":"Linux chage Command Tutorial for Beginners (6 Examples)"},"content":{"rendered":"<p>Linux command line offers several tools for user management (some of which we&#8217;ve <a href=\"https:\/\/www.howtoforge.com\/linux-adduser-addgroup-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">already discussed<\/a>). One such utility is <strong>chage<\/strong>, which lets you tweak password expiry information. In this tutorial, we will discuss this tool using some easy to understand examples. But before we dive in, it&#8217;s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-chage-command\">Linux chage command<\/h2>\n<p>The chage command, as already explained above, lets you tweak user password expiry information. Following is its syntax:<\/p>\n<p class=\"command\">chage [options] LOGIN<\/p>\n<p>And here&#8217;s what the man page says about it:<\/p>\n<pre> The chage command changes the number of days between password changes<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 and the date of the last password change. This information is used by<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the system to determine when a user must change his\/her password.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the chage command works:<\/p>\n<h2 id=\"q-how-to-view-current-password-expiry-info\">Q1. How to view current password expiry info?<\/h2>\n<p>To view current password expiry date info for a user, use the -l command line option.<\/p>\n<p class=\"command\">chage -l [USERNAME]<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p class=\"command\">chage -l himanshu<\/p>\n<p>And following is the output it produced on my system:<\/p>\n<pre>Last password change\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: Jul 26, 2018<br\/>Password expires\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0 : never<br\/>Password inactive\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: never<br\/>Account expires\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: never<br\/>Minimum number of days between password change\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 0<br\/>Maximum number of days between password change\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0: 99999<br\/>Number of days of warning before password expires\u00a0\u00a0 \u00a0: 7<\/pre>\n<p>So currently, the password is set to expire &#8216;never&#8217;.<\/p>\n<h2 id=\"q-how-to-change-password-expiry-date\">Q2. How to change password expiry date?<\/h2>\n<p>This you can do using the -M command line option, which requires you to pass a number (which refers to the maximum number of days during which a password is valid).<\/p>\n<p>For example:<\/p>\n<p class=\"command\">chage -M 1000 himanshu<\/p>\n<p>Note that this operation requires root privileges.<\/p>\n<p><a class=\"fancybox\" id=\"img-chage-m-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/chage-m-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples.png\" alt=\"How to change password expiry date\" width=\"500\" height=\"143\" title=\"\"><\/a><\/p>\n<p>So you can see in the screenshot above, the password expiry has now been set to April 21, 2021.<\/p>\n<p>Note that you can also use the <strong>-m<\/strong> command line option, which is used to set the minimum number of days between password changes. The -M option we discussed above sets the maximum number of days during which a password is valid.<\/p>\n<h2 id=\"q-how-to-change-last-password-change-date\">Q3. How to change last password change date?<\/h2>\n<p>You can tweak the last password change date using the -d command line option. As input, you can either pass a number to this option, or a complete date. Here&#8217;s how the man page explains it:<\/p>\n<pre> -d, --lastday LAST_DAY<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Set the number of days since January 1st, 1970 when the password<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 was last changed. The date may also be expressed in the format<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 YYYY-MM-DD (or the format more commonly used in your area).<\/pre>\n<p>Following is an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-chage-d-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/chage-d-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-1.png\" alt=\"How to change last password change date\" width=\"500\" height=\"143\" title=\"\"><\/a><\/p>\n<p>So you can see the value of the &#8216;Last password change&#8217; field was changed successfully.<\/p>\n<h2 id=\"q-how-to-warn-user-before-password-expires\">Q4. How to warn user before password expires?<\/h2>\n<p>The chage command also lets you set the number of days of warning before a password change is required. This can be done using the -W command line option.<\/p>\n<pre>-W, --warndays WARN_DAYS<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Set the number of days of warning before a password change is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 required. The WARN_DAYS option is the number of days prior to the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password expiring that a user will be warned his\/her password is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 about to expire.<\/pre>\n<p>For example:<\/p>\n<p class=\"command\">chage -W 10 himanshu<\/p>\n<p>This command will make sure that user gets to see password expiry warning 10 days before the password is set to expire.<\/p>\n<h2 id=\"q-how-to-lock-an-account\">Q5. How to lock an account?<\/h2>\n<p>Use the -E command line option to lock an account. The way it accepts input is similar to the -W option we discussed above. For your reference, here&#8217;s how the man page explains it:<\/p>\n<pre readability=\"6\">-E, --expiredate EXPIRE_DATE<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Set the date or number of days since January 1, 1970 on which the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 user's account will no longer be accessible. The date may also be<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 expressed in the format YYYY-MM-DD (or the format more commonly<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 used in your area). A user whose account is locked must contact the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 system administrator before being able to use the system again.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Passing the number -1 as the EXPIRE_DATE will remove an account<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 expiration date.<\/p><\/pre>\n<p>For example:<\/p>\n<p class=\"command\">chage -E 2019-06-21 himanshu<\/p>\n<p>This above command will make sure the account for user &#8216;himanshu&#8217; will become inaccessible starting June 21, 2019.<\/p>\n<h2 id=\"q-what-happens-if-chage-is-used-without-any-option\">Q6. What happens if chage is used without any option?<\/h2>\n<p>Here&#8217;s what happens in this case:<\/p>\n<pre> If none of the options are selected, chage operates in an interactive<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fashion, prompting the user with the current values for all of the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fields. Enter the new value to change the field, or leave the line<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 blank to use the current value. The current value is displayed between<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 a pair of [ ] marks.<\/pre>\n<p><a class=\"fancybox\" id=\"img-chage-no-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/chage-no-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-2.png\" alt=\"What happens if chage is used without any option\" width=\"498\" height=\"181\" title=\"\"><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>If you are a Linux system admin, or someone who is responsible for user management on Linux machines, this command is worth keeping in your kitty. We&#8217;ve covered several chage command line options here. To learn more, head to the <a href=\"https:\/\/linux.die.net\/man\/1\/chage\" target=\"_blank\" rel=\"noopener noreferrer\">chage man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-chage-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-chage-command%2F&amp;text=Linux+chage+Command+Tutorial+for+Beginners+%286+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-chage-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/08\/linux-chage-command-tutorial-for-beginners-6-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Linux command line offers several tools for user management (some of which we&#8217;ve already discussed). One such utility is chage, which lets you tweak password expiry information. In this tutorial, we will discuss this tool using some easy to understand examples. But before we dive in, it&#8217;s worth mentioning that all examples here have been [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-6232","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=6232"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/6232\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=6232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=6232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=6232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}