This command prompts you to change your own password.
-
-a, --all: Report password status on all accounts.
$ sudo passwd -a # Don't know why, but this option is not working.This will display the password status for all user accounts on the system.
-
-d, --delete: Delete the password for the named account.
$ sudo passwd -d atharv [sudo] password for prathamesh: Removing password for user atharv. passwd: Success
This will delete the password for the user "atharv", effectively disabling the account.
-
-e, --expire: Force expire the password for the named account.
$ sudo passwd -e atharv Expiring password for user atharv. passwd: SuccessThis will immediately expire the password for the user "atharv", requiring them to change it upon next login.
-
-n, --mindays MIN_DAYS: Set the minimum password age.
$ sudo passwd -n 14 atharv Adjusting aging data for user atharv. passwd: SuccessThis sets the minimum password age for the user "atharv" to 14 days.
-
-x, --maximum DAYS: Set the maximum password age.
$ sudo passwd -x 30 atharv Adjusting aging data for user atharv. passwd: SuccessThis sets the maximum password age for the user "atharv" to 30 days.
-
-i, --inactive DAYS: Specifies the number of inactive days for a user.
$ sudo passwd -i 5 atharv Adjusting aging data for user atharv. passwd: SuccessThis will set the inactivity period to 5 days for the user "atharv" after which the account will be disabled if the password is not changed.
-
-w, --warning DAYS: Set the number of days in advance the user will begin receiving warnings that her password will expire.
$ sudo passwd -w 3 atharv Adjusting aging data for user atharv. passwd: SuccessThis will gives the warning message for changing the password before 3 days of minimum days
-
-S, --status: Report password status on the named account.
$ sudo passwd -S atharv atharv NP 2024-08-31 14 30 3 5 (Empty password.)
atharv: The username for which the status is being checked.NP: It stand for "No Password", indicating that the user does not have a password set.2024-08-31: The date when the password was last changed.14: Then minimum age (days) before the password can be changed again.30: Then maximum age (days) before the password can be changed again.3: Then warning period (days) before the password has to be changed.5: The inactivity period (days) after which the account will be disabled if the password is not changed the password can be changed again.
The summary of this is, the user
atharvdows not have a password set (Empty password). The passwrod status was last changed on2024-08-31. The password cannot be changed for 14 days, must be changed after 30 days, has a warning period of 3 days, and the account will be disabled after 5 days of inactivity if the password is not changed.
Note
To use these options, you typically need to have sudo privileges.
openssl is a powerful cryptographic tool that can be used to generate encrypted passwords.
Command Breakdown:
$ sudo useradd -p $(openssl passwd password1) atharvsudo useradd: Creates a new user named "atharv".-p: Specifies the password for the new user.$(openssl passwd password1): Generates an encrypted password usingopensslwith the plain-text password "password1".
The default password settings for new users are typically defined in the /etc/login.defs file. This file contains configuration options that affect password aging, expiration, and other policies.
chage is a command-line tool used to modify password aging information for specific users.
This command allows you to change the following password configuration settings for the user "atharv":
$ sudo chage atharv
Changing the aging information for atharv
Enter the new value, or press ENTER for the default
Minimum Password Age [0]: 30
Maximum Password Age [99999]: 45
Last Password Change (YYYY-MM-DD) [2024-09-03]:
Password Expiration Warning [7]: 7
Password Inactive [-1]: 7
Account Expiration Date (YYYY-MM-DD) [-1]: 2024-12-31This command allows you to check the password configuration setting for the user "atharv":
$ sudo chage -l atharv
Last password change : Sep 02, 2024
Password expires : Oct 17, 2024
Password inactive : Oct 24, 2024
Account expires : Dec 30, 2024
Minimum number of days between password change : 30
Maximum number of days between password change : 45
Number of days of warning before password expires : 7