Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-18-2008, 04:41 AM   #1
Registered: Oct 2005
Posts: 324

Rep: Reputation: 32
combine shadow files

I have 5 mail server that will be planning to join as 1. Let's say A,B,C,D and E. The mail server that will act as 1 is A.

My first concern is how do I transfer the user account from B,C,D and E going to A while retaining their password in their previous mail server?
Emails is no concern since I can rsync the home directory.

I'm thinking of combining shadow file but is it advisable? Any software/commands that can do this? Will different OS such as Rh9, FC2 and Centos4 will be an issue even they are all rpm-like OS?
Old 04-18-2008, 05:16 AM   #2
Registered: Apr 2008
Posts: 100

Rep: Reputation: 15
This depends on a lot of things, first of all the mail server itself. Is it the same mail server application on all servers?

Some mail servers allow to set user accounts without the need for a system account. If so, then you don't have to bother with the shadow password files. If the servers run different mail server applications, then you will need a different approach for each.

To merge shadow files you will also have to merge the password files and actually have to create user accounts. You must check for matching username conflicts and also for the more likely conflict of matching UID and GID values.

It can be done with a shell script. Not easy to write, but possible. Needs careful testing before applying.

Fedora HP webcam drivers

Last edited by marquardl; 05-01-2008 at 04:49 AM.
Old 04-18-2008, 06:14 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
The /etc/passwd and /etc/shadow files also contain system users that you don't want to merge.

UID_MAX=$(awk '/^UID_MAX/{ print $2}' /etc/login.defs)
jschiwal@hpamd64:~> UID_MIN=$(awk '/^UID_MIN/{ print $2}' /etc/login.defs)
jschiwal@hpamd64:~> echo $UID_MAX
jschiwal@hpamd64:~> echo $UID_MIN
Here I extracted the UID_MIN and UID_MAX values from /etc/login.defs. Values between these values inclusively are regular users.
Here I use these UID ranges to extract the regular users from /etc/passwd:
awk 'BEGIN { FS=":" } int($3) >= '$UID_MIN' && int($3) <= '$UID_MAX' { print $1 }' /etc/passwd
You will also have a problem if there are users that have the same username. Also, if one user has a UID that is used by another user on one of the other machines.
You would also need to merge both the regular users in /etc/passwd and /etc/shadow.

If you change a users UID you also have to change the UID (ownership) of any files that the user owns, such as the mail in /var/cache/mail/.

If you have a lot of users, you might want to produce a couple of files, similar to /etc/passwd and /etc/shadow, but with extra fields in them. For example, the first field could be the username. The second field the new username. The forth field the UID of the user. The fifth, the new UID of the user. Then read in each line and if an old field differs from a new field, perform any chown on files needed before writing the new values into a new /etc/password or /etc/shadow.

You could use something like this to produce a csv file from /etc/passwd containing the regular users:
awk 'BEGIN { FS=":" } int($3) >= '$UID_MIN' && int($3) <= '$UID_MAX' { print $0 }' /etc/passwd | sed 's/:/","/g;s/^/"/;s/$/"/' >passwords
This could be read into a spreadsheet like oocalc. This would allow you to easily sort by any field or replace the UID numbers with a column of sequential integers. Sorting by the username, you could easily spot any two user names that are the same.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
combine multiple files into one file? baddah Linux - Newbie 10 09-06-2011 12:22 PM
Combine files using shell scripting ccray Linux - Newbie 14 01-12-2006 12:14 PM
Command to combine several files as a single file, etc. satimis *BSD 3 06-10-2004 04:59 AM
Best way to combine files? JockVSJock Programming 4 04-25-2004 08:38 PM
I need a program to combine text with gif files stephenoregan4 Linux - Software 1 02-16-2004 10:29 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:36 PM.

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