Change user password with one Bash command line

Viewed 17718

I am making a program with Python 2.7, I use shell commands to create new users on Ubuntu and I want to setup the password for the new user. I use command prompt (Bash) commands to create users. Is there a command line that would change user's password just with 1 shell command? I tried:

echo "newpass" | passwd --stdin user1 

but it appears the current Ubuntu 16.04 version I have doesn't have the --stdin parameter anymore. And I need that after the command is executed, the password would be set, I would not need to retype to confirm password etc (like using terminal).

4 Answers

Kindly try below one one-liner command for user & password creation

useradd himanshi ; echo -e "1234\n1234" | passwd himanshi

sudo echo -e "<yourpassword>\n<yourpassword>" | sudo passwd <user>

This helped me.

Related