Solved

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

Posted on 2008-06-10
12
2,307 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

749 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