This post will guide you how to change user password from the command line in Linux. How do I change group password under Linux operating system.
- Passwd Command
- Set User Account Password
- Changing Password for a Given User Account
- Force to Change the Password
Passwd Command
The passwd utility is used to update user’s authentication token(s). This task is achieved through calls to the Linux-PAM and Libuser API. Essentially, it initializes itself as a “passwd” service with Linux-PAM and utilizes configured password modules to authenticate and then update a user’s password.
The syntax of the Passwd is as follows:
passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username]
Option:
-e, --expire This is a quick way to expire a password for an account. The user will be forced to change the password during the next login attempt. Available to root only.
Set User Account Password
If you want to set your current logging user account from the command line in your Linux system, and you can directory to run the following passwd command, type:
$ passwd
Outputs:
[devops@mydevops ~]$ passwd
Changing password for user devops.
Current password:
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Changing Password for a Given User Account
If you want to change the password for a given user account on your Linux system, and you can pass the user name to the passwd command, type:
$ passwd username $ passwd devops
Outputs:
[devops@mydevops ~]$ sudo passwd devops
[sudo] password for devops:
Changing password for user devops.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
Force to Change the Password
If you want to force to change the password during the next login attempt, and you need to pass the option “–expiry” to the passwd command, type:
$ sudo passwd --expire devops
Outputs:
[devops@mydevops ~]$ sudo passwd --expire devops Expiring password for user devops. passwd: Success
Then you can try to exit the current ssh session and reconnect it with devops user. and you will be asked to change the password for user devops.
login as: devops devops@192.168.3.58's password: You are required to change your password immediately (administrator enforced) Activate the web console with: systemctl enable --now cockpit.socket Last login: Sat Sep 28 23:24:34 2019 from 192.168.3.54 WARNING: Your password has expired. You must change your password now and login again! Changing password for user devops. Current password: New password: Retype new password:
If you want to see more details for passwd command, and you type the following command to get more help info:
$ man passwd
or
$ passwd --help
Outputs:
[devops@mydevops ~]$ passwd --help
Usage: passwd [OPTION...] <accountName>
-k, --keep-tokens keep non-expired authentication tokens
-d, --delete delete the password for the named account (root
only); also removes password lock if any
-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)
Help options:
-?, --help Show this help message
--usage Display brief usage message
Conclusion
You should know that how to change user password using passwd command or read command on your CentOS or RHEL Linux system.