‘passwd’ Command to set or change Password for Unix / Linux User Account

The ‘passwd’ command is used to set or change  user’s password in linux. If the ‘passwd’ command is executed by normal user then it will ask for the current password and set the new password of a user who execute the command. When ‘passwd’ is executed by super user or root then it can reset the password for any user including root also.

Syntax for ‘ passwd ‘ command:

passwd [OPTION…] <User_Account_Name>

To change password of normal user (dev1) :

[dev1@localhost ~]$ passwd
Changing password for user dev1.
Changing password for dev1.
(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[dev1@localhost ~]$

To Display password status of the User Account (dev1) :

To show the password status of a user , you can use ‘passwd ‘ command with option ‘-S ‘ or  ‘–status ‘ as a root user.


[dev1@localhost ~]$ passwd -S dev1
Only root can do that.
[dev1@localhost ~]$ su –
Password:
Last login: Mon Apr 11 19:28:26 IST 2016 on pts/0
[root@localhost ~]#  passwd -S dev1
dev1 PS 2016-04-11 0 99999 7 -1 (Password set, MD5 crypt.)
[root@localhost ~]#


                            Or

[root@localhost ~]#  passwd –status dev1
dev1 PS 2016-04-11 0 99999 7 -1 (Password set, MD5 crypt.)
[root@localhost ~]#


To Delete the Password of a User Acccount (dev1) :

To delete the User Account Password ,you can use ‘ passwd ‘ command with ‘ -d ‘ or ‘–delete ‘ option as a user root.

[root@localhost ~]# passwd -d dev1
Removing password for user dev1.
passwd: Success

[root@localhost ~]#

Reset the password of User dev1:


[root@localhost ~]# passwd dev1
Changing password for user dev1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]#

To Expire the Password of User Account (dev1) :

To Expire the User Account Password ,you can use ‘ passwd ‘ command with ‘ -e ‘ or ‘–expire ‘ option as a user root.

Note:  Forces the user to change own password at the next login.

[root@localhost ~]# passwd -e dev1
Expiring password for user dev1.
passwd: Success
[root@localhost ~]#

Login again user account dev1 :


login as: dev1
dev1@192.168.198.128’s password:
You are required to change your password immediately (root enforced)
Last login: Mon Apr 11 20:13:30 2016 from 192.168.198.1
WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user dev1.
Changing password for dev1.


(current) UNIX password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.


To Lock an user Account (dev1) :

To Lock an user Account you can use ‘ -l ‘ or ‘ –lock ‘ option with the ‘passwd ‘ command as a root user.

[root@localhost ~]# passwd -l dev1
Locking password for user dev1.
passwd: Success
[root@localhost ~]#

[root@localhost ~]# cat /etc/shadow | grep dev1
dev1:!!$1$.9olNYBI$9yD4BIDM7fMOAluLvpaNo1:16902:0:99999:7:::
[root@localhost ~]#
 

 

Note:– ! mark is the sign of Locked User

 

To Unlock the password of an user account (dev1) :

 

To Unock an user Account you can use ‘ -u ‘ or ‘ –unlock ‘ option with the ‘passwd ‘ command as a root user.

 

[root@localhost ~]# passwd -u dev1
Unlocking password for user dev1.
passwd: Success
[root@localhost ~]#

 [root@localhost ~]# cat /etc/shadow | grep dev1
dev1:$1$.9olNYBI$9yD4BIDM7fMOAluLvpaNo1:16902:0:99999:7:::
[root@localhost ~]#


Minimum No. of days to change password (dev1) :

To  Set Minimum Days to Change Password,you can use ‘ passwd ‘ command with ‘ -n ‘ option as a user root.

[root@localhost ~]# passwd -n 30 dev1
Adjusting aging data for user dev1.
passwd: Success

[root@localhost ~]#’


[root@localhost ~]# chage -l dev1
Last password change                                    : Apr 11, 2016
Password expires                                        : never
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 30
Maximum number of days between password change          : 99999
Number of days of warning before password expires       : 7
[root@localhost ~]#
 

Set the Maximum No. of days to expire Password (dev1):


To  Set Maximum Days to expire Password,you can use ‘ passwd ‘ command with ‘ -x ‘ option as a user root.

[root@localhost ~]# passwd -x 365 dev1
Adjusting aging data for user dev1.
passwd: Success
[root@localhost ~]#

[root@localhost ~]# chage -l dev1
Last password change                                    : Apr 11, 2016
Password expires                                        : Apr 11, 2017
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 30
Maximum number of days between password change          : 365
Number of days of warning before password expires       : 7
[root@localhost ~]#



To Set the number of days of warning before a password change is required (dev1):

To set the warning day of an user before password expire , you can use ‘ passwd ‘ command with ‘-w ‘ option as a user root . By default the number of days of warning before password expires is set to 7. It can be changed using ‘ passwd ‘ command with ‘-w ‘ option.

[root@localhost ~]# passwd -w 25 dev1
Adjusting aging data for user dev1.
passwd: Success
[root@localhost ~]#


[root@localhost ~]# chage -l dev1
Last password change                                    : Apr 11, 2016
Password expires                                        : Apr 11, 2017
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 30
Maximum number of days between password change          : 365
Number of days of warning before password expires       : 25
[root@localhost ~]#
 

To Set inactive days after the password expire (dev1):

To set the number of days after password expiration when an account becomes disabled , you can use ‘ passwd ‘ command with ‘-i ‘ option as a user root.

[root@localhost ~]# passwd -i 32 dev1
Adjusting aging data for user dev1.
passwd: Success
[root@localhost ~]#


[root@localhost ~]# chage -l dev1
Last password change                                    : Apr 11, 2016
Password expires                                        : Apr 11, 2017
Password inactive                                       : May 13, 2017
Account expires                                         : never
Minimum number of days between password change          : 30
Maximum number of days between password change          : 365
Number of days of warning before password expires       : 25
[root@localhost ~]#

All command line options  used with the ‘ passwd ‘ command are shown below

________________________________________________________________________________

           Options                                                          Description

________________________________________________________________________________


  -k, –keep-tokens                           keep non-expired authentication tokens

  -d, –delete                         delete the password for the named account (root   only)

  -l, –lock                                        lock the password for the named account (root only)

  -u, –unlock                                   unlock the password for the named account (root only)

  -e, –expire                                    expire the password for the named account (root only)

  -f, –force                                       force operation

  -x, –maximum=DAYS                   maximum password lifetime (root only)

  -n, –minimum=DAYS                    minimum password lifetime (root only)

  -w, –warning=DAYS                     number of days warning users receives before

                                                      password expiration (root only)

  -i, –inactive=DAYS                       number of days after password expiration when an

                                                      account becomes disabled (root only)

  -S, –status                                  report password status on the named account (root  only)

  –stdin                                          read new tokens from stdin (root only)

_______________________________________________________________________________

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s