PASSWD Command Usage in Linux Explained With Examples


The passwd command changes passwords for user accounts. A normal user may only change the password for his/her own account, while the superuser may change the password for any account.passwd also changes the account or associated password validity period.

Here are few examples which will help you add more to your information about the usage of passwd command.

Usage of passwd command:
  • Change the password for an user account:

coolcoder@0:~$ sudo passwd coolcoder

Changing password for coolcoder.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully


The user is first prompted for his/her old password, if one is present. This password is then encrypted and compared against the stored password. The user has only one chance to enter the correct password.
The superuser is permitted to bypass this step so that forgotten passwords may be changed.

  • Display user account status information:

coolcoder@0:~$ sudo passwd -S coolcoder

coolcoder P 04/12/2014 0 99999 7 -1


The output consists of 7 fields. The first field is the user's login name. The second field indicates if the user account has a locked password (L), has no password (NP), or has a usable password (P). The third field gives the date of the last password change. The next four fields are the minimum age, maximum age, warning period, and inactivity period for the password. These ages are expressed in days.

  • Delete an user account's password:

This leaves the account passwordless.

coolcoder@0:~$ sudo passwd -d coolcoder

[sudo] password for coolcoder:
passwd: password expiry information changed.


Now, if you want to recreate the password, use passwd command:

coolcoder@0:~$ passwd coolcoder

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

  • Immediately expire an user account's password:

This forces the user to change his/her password at the next login.

coolcoder@0:~$ sudo passwd -e coolcoder

[sudo] password for coolcoder:
passwd: password expiry information changed.

  • Lock the password of an user account:

This option disables the password for an user account.

coolcoder@0:~$ sudo passwd -l coolcoder

[sudo] password for coolcoder:
passwd: password expiry information changed.


It actually adds a ´!´ at the beginning of the password. The passwords for the created accounts are actually stored in /etc/shadow file and are in masked form. Check the /etc/shadow file:

coolcoder@0:~$ sudo cat /etc/shadow

[sudo] password for coolcoder:
coolcoder:!$1$MJEhFr5N$i99szG3J3OsbCA9U27/ju.:16052:0:99999:7:::

  • Re-enable the locked password for an account:

coolcoder@0:~$ sudo passwd -u coolcoder

passwd: password expiry information changed.


This option re-enables a password by changing the password back to its previous value.
  • Set the minimum number of days between password changes:

coolcoder@0:~$ sudo passwd -n 0 coolcoder

passwd: password expiry information changed.


Giving 0 with -n will set the minimum number of days between password changes to 0.
  • Set the maximum number of days for the validity of the password:

coolcoder@0:~$ sudo passwd -x 99999 coolcoder

passwd: password expiry information changed.


The password will have to be changed after the maximum number of days. Giving 99999 with -x will set the maximum number of days for the validity of the password to 99999.

  • Set the number of days of warning before a password change is required:

By default the number of days of warning before password expires is set to 7. This can be changed using the following command:

coolcoder@0:~$ sudo passwd -w 10 coolcoder

passwd: password expiry information changed.

  • Perform any operation in quiet mode:

This performs the given operation in quiet mode, let me show you with an example:

coolcoder@0:~$ sudo passwd -qw 10 coolcoder
coolcoder@0:~$


Here, it quietly performed the operation without any information in the output. You can use the q option combined with other options to perform any operation quietly.

Related

linux 82742822813170069

Post a Comment

  1. Introduction
    http://www.21cssindia.com/courses/ldap-online-training-103.html
    LDAP - Overview
    A brief History of LDAP - LDAP Overview - LDAP vs. Database - LDAP Usage Summary
    LDAP Data (Object) Model - Object Tree Structure - Attributes - Object Classes
    Employees to learn at their own pace and maintain control of learning “where, when and how” with boundless access 24/7by 21st Century Software Solutions. contact@21cssindia.com ---- Call Us +919000444287

    ReplyDelete
  2. I've been using copy.com for a few days and I think it is the best
    alternative to Ubuntu One so far. The only problem is that you have to
    manually create symlinks in order to get files synchronized directly in
    your own file system. But the amount of free space they offer is
    amazing.
    If you sign in by using this referral link you'll get 20GB free and by
    referring you'll get (unlimited?) bonus space: https://copy.com?r=RS9B4K

    ReplyDelete

emo-but-icon

Translate

 

Recent Posts

comments

Recent Comments Widget

Join Us

 

Sponsored By

Recommended for you

get social

item