#1  
Old 31st August 2006, 03:13
Nate1 Nate1 is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Awk passwd

Hello Im trying to write a script to add users to the system

I have an awk script creating the users and editing the /etc/shadow file bu after I have added the users I want to insert there passwords from a file.

$1 username
$2 password

gawk -F: '{
system("passwd "$1)
then somehow enter the password twice to confirm it without user intervention
print $2
print $2
this will prompt for input for every user and then print the users password twice
}' inputfile

print doesn't work neither do a number of ways of using system, but there must be a way to do it can anyone help please
Reply With Quote
  #2  
Old 1st September 2006, 01:00
Nate1 Nate1 is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default crypt

Well i have also stumbled accross crypt 3 apparently an encryption function does anyone know how to use it?
Reply With Quote
  #3  
Old 1st September 2006, 02:27
Nate1 Nate1 is offline
Junior Member
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default answer

Well I figured it out

system("passwd --stdin "$1" < "filename")

this will force the password command to take the data from the file and give it to the user $1, and you can pipe the command to input the appropriate record.
Reply With Quote
  #4  
Old 1st September 2006, 17:03
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 31,843
Thanks: 781
Thanked 1,557 Times in 1,476 Posts
Default

Quote:
Originally Posted by Nate1
system("passwd --stdin "$1" < "filename")
Good to know.
__________________
Falko
--
Follow me on:
Reply With Quote
  #5  
Old 3rd September 2006, 20:58
drks drks is offline
Junior Member
 
Join Date: Aug 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know about the whole using a file business, but this can just as easily be done using usermod after you create the user. You will of course have to have a way to crypt the password... for that reason, I use perl and Crypt::PasswdMD5 which might suit someone else's needs better. Reference the following:

Code:
#!/usr/bin/perl -w

use strict;
use Crypt::PasswdMD5;

my $username = "johnny";
my $clearPasswd = "johnnypass";
my $cryptPasswd = "";
my $salt = rand(99);

$cryptPasswd = unix_md5_crypt($clearPasswd, $salt);

system("useradd -m -d /home/$username $username");
system("usermod -p '$cryptPasswd' $username");

print "Username is $username, using password hash $cryptPasswd\n\n";

You would of course want to make a real script that allows you to dynamically read in the usernames, loop through them, etc... but this is how to use Perl to generate the md5 hash password, and usermod to set it dynamically.

Note that Crypt::PasswdMD5 is not generally standard for Perl installs. For Debian, you should be able to apt-get this:

Code:
apt-get update && apt-get install libcrypt-passwdmd5-perl

For any standard PERL install, you can also just use CPAN:

Code:
perl -MCPAN -e shell

cpan> install Crypt::PasswdMD5

Hope that is useful.
__________________
drks - http://www.5dollarwhitebox.org

Last edited by drks; 3rd September 2006 at 21:02.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with passwd and new user creation on Sarge Skirmantas Installation/Configuration 10 1st September 2006 19:32
ispconfig setup and mysql glt50 Installation/Configuration 9 18th July 2006 13:18
Having problems with stats changin password lyndros Installation/Configuration 18 6th July 2006 08:47
ISPConfig + Passwd (Horde module)? skdb Installation/Configuration 4 15th June 2006 17:57
Passwd File latcarf Server Operation 4 30th August 2005 02:18


All times are GMT +2. The time now is 18:23.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Sponsored Links: Unified Communications: Thoughts, Strategies and Predictions
Join the discussion.
www.seamlessenterprise.com

IP Convergence
Integrate your wireless and wireline networks.
Learn how from the experts at Sprint.
www.seamlessenterprise.com

Wireless & Wireline Integration
Thoughts, strategies and solutions: join the discussion
www.seamlessenterprise.com

Unified Communications 2009
Join the Discussion. Now.
www.seamlessenterprise.com

Red Hat Virtual Experience - a free virtual event. Dec. 9th