{"id":6137,"date":"2021-05-02T22:05:26","date_gmt":"2021-05-02T22:05:26","guid":{"rendered":"https:\/\/linuxways.net\/?p=6137"},"modified":"2021-05-02T22:05:26","modified_gmt":"2021-05-02T22:05:26","slug":"how-to-force-user-to-change-password-at-next-login-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-force-user-to-change-password-at-next-login-in-linux\/","title":{"rendered":"How to Force User to Change Password at Next Login in Linux"},"content":{"rendered":"<p>Once you have created a new user on your Linux system, you may need to prompt them to change the password at the next login to comply with the password policy. This ensures that they set a different password &#8211; and a strong one for that matter- to thwart any brute-force attempts by malicious users or hackers. This ensures the safety of the user\u2019s account.<\/p>\n<p>There are two ways of compelling a user to change the password at the next login. We have used Ubuntu 20.04 for demonstration.<\/p>\n<h2><strong>Force user to change password using passwd command<\/strong><\/h2>\n<p>The passwd command is mostly used to assign or change a user\u2019s password on a Linux system. For instance, to reset the password of a user called bob, simply execute the command below as root user:<\/p>\n<pre><strong># passwd bob<\/strong><\/pre>\n<p>You will be prompted to provide a new password for the user account and later confirm it as shown.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"254\" class=\"wp-image-6138\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-381.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-381.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-381-300x104.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/p>\n<p>Aside from setting or changing a user\u2019s password, the <strong>passwd <\/strong>command can also be used to compel the user to change the password once they attempt to log in the next time.<\/p>\n<p>This is possible using the syntax provided.<\/p>\n<pre><strong># passwd -e [username]<\/strong><\/pre>\n<p>The <strong>-e <\/strong>option (also expressed as <strong>&#8211;expire)<\/strong> simply expires the user account\u2019s password and forces the user to change the password on the next logon.<\/p>\n<p>For example, to retire <strong>bob\u2019s <\/strong>password simply run the command<\/p>\n<pre><strong># passwd -e bob<\/strong><\/pre>\n<p>OR<\/p>\n<pre><strong># passwd -- expire bob<\/strong><\/pre>\n<p>Thereafter, you can verify the password expiry or aging information by running the <strong>chage <\/strong>command as shown.<\/p>\n<pre><strong># chage -l bob<\/strong><\/pre>\n<p>From the output, we can clearly observe that the password for user <strong>bob <\/strong>need\u2019s to be changed on next logon.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"351\" class=\"wp-image-6139\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-382.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-382.png 788w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-382-300x134.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-382-768x342.png 768w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/strong><\/p>\n<p>On the next login attempt, the user <strong>bob <\/strong>will get a notification that their password has expired and should be changed before proceeding. The user will be required to first provide the previously used password, then enter the new password and then confirm it as shown below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"280\" class=\"wp-image-6140\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-383.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-383.png 663w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-383-300x127.png 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/p>\n<h2><strong>Force user to change password using chage command<\/strong><\/h2>\n<p>As we have previously, the <strong>chage<\/strong> command gives insights about the user\u2019s aging information. You can also use the command to expire a user\u2019s password and force them to change it on next logon.<\/p>\n<p>You can achieve this using the <strong>-d<\/strong> option followed by 0 which implies day zeo. Also, you can use the <strong>&#8211;lastday<\/strong> flag that specifies the number of days since the epoch ( January 1, 1970)<\/p>\n<p>The syntaxes are provided below<\/p>\n<pre><strong># chage -d 0 [username]<\/strong><\/pre>\n<p>OR<\/p>\n<pre><strong># chage --lastday 1970-01-01 [username]<\/strong><\/pre>\n<p>For example, you can expire a user called <strong>jack <\/strong>as shown.<\/p>\n<pre><strong># chage -d 0 jack<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"839\" height=\"332\" class=\"wp-image-6141\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-384.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-384.png 839w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-384-300x119.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-384-768x304.png 768w\" sizes=\"auto, (max-width: 839px) 100vw, 839px\" \/><\/strong><\/p>\n<p>When user <strong>jack <\/strong>tries to log in the next time, he will be required to change his password in the same manner as demonstrated in the first part of this guide.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"226\" class=\"wp-image-6142\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-385.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-385.png 660w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/04\/word-image-385-300x103.png 300w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/strong><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>In this tutorial, we have highlighted two commands that you can conveniently use to force a user to change their password. If you were having such a challenge, it\u2019s our hope that you have gained enough insights on the matter.<\/p>","protected":false},"excerpt":{"rendered":"<p>Once you have created a new user on your Linux system, you may need to prompt them to change the password at the next login to comply with&hellip;<\/p>","protected":false},"author":1,"featured_media":6235,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[215,100],"class_list":["post-6137","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-password","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=6137"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6137\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/6235"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}