Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been banging my head on this little project the past few days and here is how it goes...

I need to organize all the UIDs for multiple servers so all users have the same UID in their /etc/passwd. Obviously I am trying to find a proper script for this so I do not have to do this manually.

If I have 1 correct server with the correct UIDs could someone recommend a manageable script to sync other servers /etc/passwd with the correct one?

I got as far as orgizing it with using

awk -F ':' '{print$1,$3}' /etc/passwd  

Then I can use diff or sort to compare the updated passwd file with the old passwd file.

share|improve this question
please post samples with an exemple of what you want before and after (you can conceal sensible parts) – Benoit Sep 20 '11 at 14:54
For an actual solution, stop keeping network-wide accounts in /etc/passwd. There are NIS and LDAP for that. – grawity Sep 20 '11 at 14:57
Thanks for the quick response. I here is what I would like to have Server 1 (incorrect UIDs) /etc/passwd jspasser:x:509 mrayes:x:507 ssmith:x:501 ljackson:x503 Server 2 (correct UIDs) jspasser:x:1001 mrayes:x:1001 ssmith:x:1002 ljackson:x:1003 – John Smith Sep 20 '11 at 15:10
@ grawity... good point, someone else brought that up in the past but its kinda out of our hands to make that decision:( . thanks – John Smith Sep 20 '11 at 15:15
up vote 0 down vote accepted

grawity has the right idea in his comment...if it had to be a script, it would need to be pretty complicated to work without a in change all uids to something crazy high then to the right base number with usermod

it would be way easier in python...and i think that's included in most linux distros as standard now. if you need a python script that does the work, say so.

#!/usr/bin/env python
import subprocess, shlex

newlistolists = []
with open('/root/masterpasswd', 'r') as newetcpass:
    for line in newetcpass:
        alist = line.split(':')

for entry in newlistolists:
    cmd = 'usermod -o -u ' + entry[2] + ' ' + entry[0]
    thecmd = shlex.split(cmd)

#insert additional logic for setting groups, shells, etc with relevant commands
#you need to do some error handling too, but it's a fast ugly UID set script

Only include usernames you want to change in /root/masterpasswd

share|improve this answer
I would be most appreciated if you could supply a python script to make this work. I am trying to do this for myself now but I am not sure if its being done correctly. thanks in advance – John Smith Sep 20 '11 at 17:54
Works in my still need to worry about groups etc – RobotHumans Sep 20 '11 at 19:04
thank you soo much for this. This helped me quite a bit! consider this thread resolved – John Smith Sep 20 '11 at 19:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.