Solved

What is the ubuntu/debian equivalent of --stdin?

Posted on 2008-06-10
12
2,418 Views
Last Modified: 2013-12-16
I am trying to reset users passwords to what is included in a txt file using --stdin, but I'm getting this error message. What do I need to do to get passwrd to recognize this option? Is there a way around this error? Here is my script:

cat userlist.txt | while read line
do
       echo $2 | passwd --stdin $1
done

Anyone have a better way of doing this? The text file is set up like this: ("user" "password")

user1 34rthd
user2 jgh564
user3 po974e
user4 hew21t
0
Comment
Question by:martingoya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 9

Expert Comment

by:michofreiha
ID: 21753379
you need to change password for a specific user?If yes use this:

#passwd user
0
 

Author Comment

by:martingoya
ID: 21753406
I need to change the password for all users listed in my file to a new password, also listed in the same file. I need the script to cycle thru the text file and change the password for each individual user to that new password. I don't want to do this individually because there are a few hundred users. The users are already created.
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 21753496
First create a file which contains all the user name. Something like this:

user1
user2
mrahman
farid
rubi
sankar
Save the file as userlist.txt. Now create the following bash file:

#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done

Save the file and exit.

chmod 755 userlist.txt

Now run the file:

./userlist.txt

This will add all the users to the system. Now we have to change the passwords. Let's say we want username123 as password. So for user nayeem the password will be nayeem123, rubi123 for user rubi and so on.

Create another bash file as follows:

#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd -stdin "$i"
echo; echo "User $usernames password changed!"
done

Run the file. All the passwords are changed.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:michofreiha
ID: 21753530
I gave you the whole solution..In your case begin with chmod 755 userlist.txt and continue till end
0
 

Author Comment

by:martingoya
ID: 21754781
still getting this error
passwd: unrecognized option '--stdin'

--stdin is not an option for passwd in ubuntu/debian

I need a way around this or use another option to get the job done
0
 
LVL 9

Accepted Solution

by:
michofreiha earned 350 total points
ID: 21755036
you can use "chpasswd"...This command will help you to solve the problem
0
 
LVL 9

Expert Comment

by:michofreiha
ID: 21755079
or
don't make up options to passwd. There's a --password option to useradd you could use.
0
 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 150 total points
ID: 21755509
Are you saying you are familiar with a distribution whare passwd has the non-standard option --stdin? What distribution was that?

Adjust your input file to conform with the format required by "chpasswd". Type "man chpasswd" to find out what that is. It will do the job.
0
 
LVL 23

Expert Comment

by:Mysidia
ID: 21756841
Check that ''useradd', ''usermod', and perl  are available on your system.
And:

perl -e 'use Digest::MD5 qw/md5_base64/; while(<>){if (/^(\S+)\s+(\S+)$/) {
$salt=substr(md5_base64(`hexdump /dev/urandom |head -1`),0,5); print "useradd $1\nusermod $1 -p " . crypt($2, q[$1$] . $salt)."\n\n"; }}'


So, for example,  the output would look like:

useradd user1
usermod user1 -p $1$W3qTE$dCXWwrkWzU5KhqzjMwAXN/

useradd user2
usermod user2 -p $1$xKnIa$PQ4P71clTYr3on.6jngBl.

useradd user3
usermod user3 -p $1$bnqQY$F507tdAouXhHVeulT4fT6/

useradd user4
usermod user4 -p $1$0X1zt$bsFm4olT.J97FlUvx9ia8.




Save the output to another file and exec in the shell.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21757110
Your script should look like
while read user password
do
       echo $password | passwd --stdin $user
done <userlist.txt

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 21757279
Hi Tintin,

this is a question related to another question where I proposed a similar solution, but the question is that ubuntu passwd command does not support --stdin option.
0
 

Author Closing Comment

by:martingoya
ID: 31465851
chpasswd command was exactly what I needed...thanks!
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question