Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing input into passwd using pipe

How can I pipe some input using echo, into program that requires user typing something two times?

for example

echo "somepassword"|passwd someuser

creates this error message

Enter new UNIX password: Retype new UNIX password: passwd: Authentication token manipulation error
passwd: password unchanged

because I didn't retyped password

like image 776
user3667832 Avatar asked May 23 '14 07:05

user3667832


People also ask

How do you pass a password in passwd command?

passwd --stdin <username> This command will read from the echo command and pass it to the passwd command. So this will set the user1 password to userpasswd1.

How do I password a bash script?

#!/bin/bash password="" echo "Enter Username : " # it will read username read username pass_var="Enter Password :" # this will take password letter by letter while IFS= read -p "$pass_var" -r -s -n 1 letter do # if you press enter then the condition # is true and it exit the loop if [[ $letter == $'\0' ]] then break fi ...


1 Answers

You need to send the password twice:

(echo 'somepassword'; echo 'somepassword') | passwd someuser
like image 134
Barmar Avatar answered Sep 22 '22 13:09

Barmar