LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-09-2007, 09:34 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
batch set passwords


I have a file formatted as username,password I need to set each users password to the one in the file, I have tried:
<code>
usermod -p 'password' username
</code>
This exits fine, but the new password does not work.
<code>
echo "password
password" | passwd username
</code>

I can parse the file fine and use it in a command line, I just need a command that lets me set the password in a non-interactive way.
 
Old 07-09-2007, 10:43 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Create a small TCL/Expect script to set the password, and call it setpw:

Code:
#!/usr/bin/expect -f     
spawn passwd [lindex $argv 0]
set password [lindex $argv 1]
expect "password:"
send "$password\r"
expect "password:"
send "$password\r"
expect eof
You can then run 'setpw userid password' from the command line or a script as root.
 
Old 07-09-2007, 11:01 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Does your shadow package include the newusers command? If so, it should do what you need. From the man page:
Code:
NAME
       newusers - update and create new users in batch

SYNOPSIS
       newusers [new_users]

DESCRIPTION
       newusers reads a file of user name and cleartext password pairs and uses this information to
       update a group of existing users or to create new users.  Each line is in the same format as
       the standard password file (see passwd(5)) with the following exceptions.
 
Old 07-10-2007, 04:44 AM   #4
edenCC
Member
 
Registered: May 2006
Location: China
Distribution: Debian
Posts: 198
Blog Entries: 1

Rep: Reputation: 32
It's better to have a try with 'chpasswd'

# rpm -qf /usr/sbin/chpasswd
pwdutils-3.0.7.1-17.10
# echo edencc:IsThisYouPd|chpasswd
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Request : set passwords for many users [user accounts exist] using a shell script bv_uma Linux - Software 3 08-19-2006 09:01 AM
Need shell script to set passwords for already created users naren_0101bits Programming 2 08-28-2005 02:02 PM
Completely uninstalling MySQL and its passwords passwords...how? I locked myself out! Baix Linux - Newbie 2 01-30-2005 04:10 PM
Cant set passwords for new users ribbones Linux - Newbie 2 09-03-2003 10:52 AM
Batch change passwords petertm Linux - Newbie 3 02-06-2003 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 06:52 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration