Solved

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

Posted on 2008-06-10
12
2,110 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
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
 
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
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…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now