{"id":4763,"date":"2018-06-08T12:35:44","date_gmt":"2018-06-08T08:35:44","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-passwd-command\/"},"modified":"2018-06-08T12:35:44","modified_gmt":"2018-06-08T08:35:44","slug":"linux-passwd-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-passwd-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux passwd Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>As a Linux command line user, you should be aware of\u00a0utilities that help you with user-account management. Once such tool is <strong>passwd<\/strong>, which lets you change your account password. In this tutorial, we will discuss the basics of this command using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples in this tutorial have been tested on an Ubuntu 16.04 LTS machine.<\/p>\n<h2 id=\"linux-passwd-command\">Linux passwd command<\/h2>\n<p>As already mentioned in the beginning, the passwd command lets users change their account password. Following is its syntax:<\/p>\n<p class=\"command\">passwd [options] [LOGIN]<\/p>\n<p>And here&#8217;s how the man page describes it:<\/p>\n<pre> The passwd command changes passwords for user accounts. A normal user<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 may only change the password for his\/her own account, while the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 superuser may change the password for any account.\u00a0 passwd also changes<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the account or associated password validity period.<\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how this command works.<\/p>\n<h2 id=\"q-how-to-use-passwd\">Q1. How to use passwd?<\/h2>\n<p>Basic usage is simple &#8211; just execute the passwd command sans any option\/input.<\/p>\n<p class=\"command\">passwd<\/p>\n<p>Following is some useful information that you need to know about passwd&#8217;s operation:<\/p>\n<pre readability=\"28\"> The user is first prompted for his\/her old password, if one is present.<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 This password is then encrypted and compared against the stored<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 password. The user has only one chance to enter the correct password.<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The superuser is permitted to bypass this step so that forgotten<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 passwords may be changed.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 After the password has been entered, password aging information is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 checked to see if the user is permitted to change the password at this<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 time. If not, passwd refuses to change the password and exits.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The user is then prompted twice for a replacement password. The second<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 entry is compared against the first and both are required to match in<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 order for the password to be changed.<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Then, the password is tested for complexity. As a general guideline,<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 passwords should consist of 6 to 8 characters including one or more<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 characters from each of the following sets:<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00b7\u00a0\u00a0 lower case alphabetics<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00b7\u00a0\u00a0 digits 0 thru 9<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00b7\u00a0\u00a0 punctuation marks<\/p><p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Care must be taken not to include the system default erase or kill<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 characters.\u00a0 passwd will reject any password which is not suitably<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 complex.<\/p><\/pre>\n<p>For example, in my case, here&#8217;s how I changed the passwd:<\/p>\n<p><a class=\"fancybox\" id=\"img-passwd-basic-usage\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/passwd-basic-usage.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-passwd-command-tutorial-for-beginners-8-examples.png\" alt=\"\" title=\"\"><\/a><\/p>\n<p>Please note that in case you have superuser\u00a0privileges (or are a system admin), you can change any account&#8217;s password by just mentioning the username of the account. For example:<\/p>\n<p class=\"command\">passwd himanshu<\/p>\n<h2 id=\"q-how-to-make-an-account-passwordless\">Q2. How to make an account password-less?<\/h2>\n<p>The passwd command also lets you delete a password associated with a user account. For this, you need to use the -d command line option.<\/p>\n<p class=\"command\">passwd -d<\/p>\n<p>So this is basically a quick way to disable password for an account, essentially making it password-less.<\/p>\n<h2 id=\"q-how-to-forcibly-expire-a-password\">Q3. How to forcibly expire a password?<\/h2>\n<p>Sometimes the system admin may want a user to change their password immediately. So in that case, they may use the -e command line option which results in immediate expiry of the password, forcing user to change their password on the very next login.<\/p>\n<p class=\"command\">passwd -e<\/p>\n<h2 id=\"q-how-to-disable-an-account-if-password-remains-expired\">Q4. How to disable an account if password remains expired?<\/h2>\n<p>The passwd command also lets you deal with situations where-in user doesn&#8217;t take any action even after their password is expired. Basically, the tool lets you disable the account altogether in case password remains expired for a set number of days. This you can do using the -i command line option, which requires a number as input.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">passwd -i 5<\/p>\n<p>So this command will make sure the account is disabled if the password remains expired for 5 days.<\/p>\n<h2 id=\"q-how-to-set-a-time-gap-between-password-changes\">Q5. How to set a time gap between password changes?<\/h2>\n<p>The passwd command also allows you to set a minimum time gap between password changes. This is made possible through the -n command line option, which requires a numeric value that&#8217;s treated as number of days.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">passwd -n 10<\/p>\n<p>This command makes sure there&#8217;s a gap of 10 days between any two password changes. It&#8217;s worth mentioning that a value of 0 indicates that the user may change his\/her password at any time.<\/p>\n<h2 id=\"q-how-to-make-passwd-display-account-status-info\">Q6. How to make passwd display account status info?<\/h2>\n<p>This you can do using the -S command line option.<\/p>\n<p><a class=\"fancybox\" id=\"img-passwd-s-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/passwd-s-option.png\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-passwd-command-tutorial-for-beginners-8-examples-1.png\" alt=\"\" title=\"\"><\/a><\/p>\n<p>Here&#8217;s how the official documentation explains these fields:<\/p>\n<pre> Display account status information. The status information consists<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 of 7 fields. The first field is the user's login name. The second<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 field indicates if the user account has a locked password (L), has<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 no password (NP), or has a usable password (P). The third field<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 gives the date of the last password change. The next four fields<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 are the minimum age, maximum age, warning period, and inactivity<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 period for the password. These ages are expressed in days.<\/pre>\n<h2 id=\"q-how-to-set-password-validity-period\">Q7. How to set password validity period?<\/h2>\n<p>The passwd command allows you to do this through its -x option, which requires a number representing the maximum number of days a password remains valid.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">passwd -x 100<\/p>\n<h2 id=\"q-how-to-make-passwd-warn-users-about-due-password-change\">Q8. How to make passwd warn users about due password change?<\/h2>\n<p>This can be done using the -w command line option, which requires a number as input, which is nothing but number of days prior to the password expiring that a user will be warned that his\/her password is about to expire.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">passwd -w 7<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>So you can see passwd is a very important tool that you should be aware of regardless of the type of user you are (newbie or pro). Here, in this tutorial, we have discussed several key features of passwd. Practice these, and once you&#8217;re done, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/5\/passwd\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to know more about it.<\/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-passwd-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-passwd-command-tutorial-for-beginners-8-examples-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-passwd-command%2F&amp;text=Linux+passwd+Command+Tutorial+for+Beginners+%288+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\/06\/linux-passwd-command-tutorial-for-beginners-8-examples-3.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\/06\/linux-passwd-command-tutorial-for-beginners-8-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-passwd-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-passwd-command-tutorial-for-beginners-8-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>As a Linux command line user, you should be aware of\u00a0utilities that help you with user-account management. Once such tool is passwd, which lets you change your account password. In this tutorial, we will discuss the basics of this command using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that &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-4763","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4763","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=4763"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4763\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=4763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=4763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=4763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}