Solved

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

Posted on 2008-06-10
12
2,076 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
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.

 
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.

Join & Write a Comment

This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
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.

743 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

15 Experts available now in Live!

Get 1:1 Help Now