?
Solved

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

Posted on 2008-06-10
12
Medium Priority
?
2,537 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
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit 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 1050 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 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 450 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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

764 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