Method 1: passwd

Conventionally the command use to change password on Linux based system is passwd
, the option related to this command is –stdin ,an this is all done throughout a pipe.
echo -e "new_password\nnew_password" | (passwd --stdin $USER)

Method 2: chpasswd

Another alternative is to use the chpasswd, explain as below:
echo "password:name" | chpasswd
Note that the first method can be use to change psssword on Samba based system:
echo -e "new_password\nnew_password" | (smbpasswd -a -s $USER)