A few words of thanks would be greatly appreciated.

Changing Password Via a Script

To change a password in Linux through a Bash script, he two scripts that are most important are 'Create Users' and 'Change Passwords Shell' scripts, for the system admin which regularly uses the mail servers, as there might be multiple functionalities associated with the admin job. If there is a failure to backup the admin's system username and password, it hampers other admin tasks and chances of password misappropriation are high. If you lose the usernames and passwords of the mail server, the admin has to manually create all the users again and then change the passwords for all of them. There are two methods to change passwords on the system if you are using the Linux operating system .The conventional command is passwd, -stdin, pipe. One more option that can be used is the chpasswd.

Method 1: passwd

Conventionally, the command use to change a password on a Linux based system is passwd. The option related to this command is -stdin , and this is all done through a pipe

echo -e "new_password\nnew_password" | (passwd --stdin $USER)

Method 2: chpasswd

An alternative is to use chpasswd, as below:

echo "password:name" | chpasswd

Note that the first method can be use to change the password on Samba based system:

echo -e "new_password\nnew_password" | (smbpasswd -a -s $USER) 

Photo by Caspar Camille Rubin on Unsplash


A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Changing Password Via a Script », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).
1 Comment