bashshellubuntudebianpasswd

how to run "sudo passwd username" noninteractively


In a shell script with sudo privileges, I'm trying to change another users password.

I tried sudo passwd username but didn't get anywhere.


Solution

  • You need to use the chpasswd command. You can try something like this:

    echo "username:password" | sudo chpasswd
    

    I used it many times. It worked for me.