Re: Syncronizing passwords on multiple servers

Stephen Carville <[email protected]> Wed, 11 Jun 2003 20:51:43 -0700
Newsgroups gmane.linux.redhat.release.enigma
Organization Far Side of the Moon
Message-ID <[email protected]>
On Monday 02 June 2003 01:38 pm, Andy Carse wrote:
> Hi, I will have to RH 7.2 boxes running shortly and I would like to 
be able to sync the users passwords on both 
> without them having to logon to each box separately to change their 
passwords.
> 
> Is there an easy way of accomplishing this?

Ive been trying to come up with a good way to o this and still keep 
passwords local to each machine.  Best I've come up with is to have 
users change passwords on some 'master' server and them copy the 
information from there to the other machines.  Here is script I use 
to help.  It juist prints the command you would use.

#!/usr/bin/perl -w

# copy an account
use strict;

my $CAT = "/bin/cat";
my $ID = "/usr/bin/id";
my $GROUP = "/etc/group";
my $SHADOW = "/etc/shadow";
my $PASSWD = "/etc/passwd";

# commands not executed
my $USERADD = "/usr/sbin/useradd";
my $USERMOD = "/usr/sbin/usermod";

my ($username,$line,$command);
my ($name,$pw,$uid,$gid,$gecos,$home,$shell,$list,$groups);
my (@results,@dope);

($username) = @ARGV;

unless ($username) { die; }

# get the passwd file info
@results = `$CAT $PASSWD`;

$command = "";
foreach $line (@results) {
  chomp $line;
  ($name,$pw,$uid,$gid,$gecos,$home,$shell) = split /:/,$line;
  if ($name eq $username) {
    $command = "$USERADD -u $uid -g $gid -d $home -s $shell";
    if ($gecos) {
      $command .= " -c \'$gecos\'";
    }
    $command .= " $username";
    last;
  }
}

if ($command) {
  print "$command\n";
} else {
  die "User: $username not found";
}

# now get auxiliary group information
@results = `$CAT $GROUP`;
foreach $line (@results) {
  chomp $line;
  ($name,$pw,$gid,$list) = split /:/, $line;
  if ($list =~ m/$username/) {
    $groups .= "$name,";
  }
}

if ($groups) {
  chop $groups;
  print  "$USERMOD -G $groups $username\n";
}

# finally the password (got root?)
#command = "":
@results = `$CAT $SHADOW`;
foreach $line (@results) {
  chomp $line;
  ($name,$pw,@dope) = split /:/, $line;
  if ($name eq $username) {
    $command = "$USERMOD -p \'$pw\' $username";
    last;
  }
}

if ($command) {
  print "$command\n";
} else {
  die "No password entry for $username";
}


> 
> TIA 
> Andy 
> 

-- 
Stephen Carville
------------------------------------------------------------------
Mom & Pop were just a couple of kids when they got married. He was
eighteen, she was sixteen and I was three."
 -- Billie Holiday