Reputation: 519
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).
Upvotes: 9
Views: 41091
Reputation: 2861
sudo echo -e "<yourpassword>\n<yourpassword>" | sudo passwd <user>
This helped me.
Upvotes: 4
Reputation: 807
Kindly try below one one-liner command for user & password creation
useradd himanshi ; echo -e "1234\n1234" | passwd himanshi
Upvotes: 7
Reputation: 8544
Please see the man chpasswd(8): man 8 chpasswd
The chpasswd command reads a list of user name and password pairs from
standard input and uses this information to update a group of existing
users. Each line is of the format:
user_name:password
Based on the man you can use:
echo 'user:passwd' | sudo chpasswd
Upvotes: 21