Find the answer to your Linux question:
Results 1 to 10 of 10
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Bash script to change the current user password

    I am looking for a way to change the current user password form a bash script I have. Here is what I have tried:

    echo -e "$password1\n$password1" | passwd $username
    I get a Authentication token manipulation error
    passwd: password unchanged error.

    I even tried to use expect but for some reason it hangs at the first prompt asking for the original password.

    Any ideas how I can do this?


  2. #2
    Linux Guru
    Join Date
    Dec 2013
    are you running the bash script as root/superuser?
    please show us the complete script,
    and the exact command you use to execute it.

  3. #3
    Previously I was not running it as su or root , I am now. Here is my script

  4. $spacer_open
  5. #4
    IP=$(ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f 1)
    MAC=$(ip link show eth0 | awk '/ether/ {print $2}')
    echo "Enter the Dealer name:"
    read dealer
    echo " Enter the Deployment ID:"
    read serial
    echo "IP Address: $IP"
    echo "MAC Address: $MAC"
    #echo -n $MAC | md5sum | cut -d" " -f1
    md5=$(echo -n "$MAC" | md5sum | cut -f1 -d' ')
    echo " $md5"
    cat > Nimbusinfo.txt << EOF
    The MAC address of this machine is : $MAC
    This is the new Root Password : $md5
    This system sold was to: $dealer
    The serial number of this system is: $serial
    set password ewl062852
    echo -e "$password\$password" | passwd

    # EndOfFile

  6. #5
    Sorry for the broken posts. The forum wasn't allowing a part of my script to be posted since I have less than 15 posts. Here is the error I am getting now.

    Changing password for user root.
    New password: BAD PASSWORD: it is based on a dictionary word
    Retype new password: Password change aborted.
    New password: Password change aborted.
    New password: Password change aborted.
    passwd: Have exhausted maximum number of retries for service

  7. #6
    Linux Newbie
    Join Date
    Aug 2009
    Mumbai, India
    Firstly you have a typo in your code:
    HTML Code:
    echo -e "$password\$password" | passwd
    should actually be
    HTML Code:
    echo -e "$password\n$password" | passwd
    . You are missing the "n" after "\"

    I'm not sure about the set command you use prior to the above mentioned line. I presume you want to set the value of the variable password to something. In that case use


  8. #7
    Linux Guru
    Join Date
    Dec 2013
    if the problem is with the echo command, you can also try yes instead:
    yes $password | passwd edlentz
    if you don't specify the user whose password you want to change, it defaults to the root user.
    but, you said you want to change the current user's password, so you have to specify the curreent user. in my example i assumed that is "edlentz".
    additionally, if you changed the root password while being another user, you'd need to enter root's password, which poses additional difficulties in scripts. so let's stick to the current user.

  9. #8
    It weird. I run it on my Ubuntu and it works fine.

  10. #9
    Shoot I thought I responded to this working along time ago. The help I got from syd05 and nihili fixed my issues Thanks Sultanka for checking this . We can colose this thread.

    Thanks again everyone

  11. #10
    Linux Guru budman7's Avatar
    Join Date
    Oct 2004
    Knee deep in Grand Rapids, Michigan
    To close the thread, just mark it as "Solved" using the thread tools.
    If you want to learn more about linux take a linux journey
    Use CODE tags when posting output of commands. Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts