1832418 Members
3467 Online
110042 Solutions
New Discussion

Duplicate uid's

 
SOLVED
Go to solution
S.Rider
Regular Advisor

Duplicate uid's

I thought pwck checked for duplicate uids, but I guess not. Strange because grpck does check for duplicate group id numbers.
Anyone know of a command that checks for duplicate uids ? I recently found some dups on one of the recently built servers and I want to check the other 90 to see how widespread the issue is.
Actually I think I'll end up writing the script to check each servers password file against what we refer to as the "master password file" on one server. All other servers are supposed to have had uid's and names assigned from this one master but I'm learning this isn't the case.

Just hoping someone out there has a check-for-duplicate-uid script to save me a few steps.
Ride Boldly Ride, but watch out for El Dorado's
9 REPLIES 9
Paul Sperry
Honored Contributor
Solution

Re: Duplicate uid's

Hi Jay

awk -F: '{ print $3 }' /etc/passwd | sort | uniq -d


you extract all UIDs, sort them, and print only duplicates lines. Simple one liner.


A. Clay Stephenson
Acclaimed Contributor

Re: Duplicate uid's

Here's one that will check for duplicate logins and duplicate uid's, dupacct.sh. If any are found, output is written on stdout. No news is good news.
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Duplicate uid's

Hi Jay:

This script will print out the duplicate UIDs (if any):

#!/usr/bin/perl
use strict;
my %user;
my ($name, $uid);

while (($name,undef,$uid) = getpwent) {
$user{$uid}++;
}
foreach $uid (keys %user) {
print $uid, "\n" if $user{$uid} > 1;
}
1;

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: Duplicate uid's

Hi (again) Jay:

Here's a better version. This script finds any duplicate UIDs and reports them along with the associated usernames. Nothing is reported if no duplicates exist.

#!/usr/bin/perl
use strict;
my %user;
my ($name, $uid);

while (($name,undef,$uid) = getpwent) {
push( @{$user{$uid}}, $name );
}
foreach $uid (sort keys %user) {
print "$uid = @{$user{$uid}}\n" if ($#{$user{$uid}}) > 0;
}

...For example:

103 = jay jaykoonz koonz
107 = oper operator

Regards!

...JRF...
Sundar_7
Honored Contributor

Re: Duplicate uid's

I must be missing something. Why do you have to write perls and C when you already have the logins command ?

logins -d will list the user accounts with duplicate IDs.
Learn What to do ,How to do and more importantly When to do ?
Rick Garland
Honored Contributor

Re: Duplicate uid's

The logins command has a switch for checking dup UIDs.

Other options available. do 'man logins'
James R. Ferguson
Acclaimed Contributor

Re: Duplicate uid's

Hi Sundar:

You wrote, "Why do you have to write perls and C when you already have the logins command ?".

I suppose I could answer, "For fun, of course!". While that is true, I had flat forgotten about the 'logins' command :-))

Thanks!

Regards!

..JRF...
Sundar_7
Honored Contributor

Re: Duplicate uid's

James,

Being an avid scripter myself, I would agree with you it is "fun". Take no offense but I would rather invest my energy in something that is not readily available

Sundar.
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor

Re: Duplicate uid's

Mainly because the logins command is a non-standard command so that if one has to do the check across multiple flavors of UNIX, one would like a one-size-fits-all command.
If it ain't broke, I can fix that.