LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 04-18-2008, 03:41 AM   #1
packets
Member
 
Registered: Oct 2005
Posts: 280

Rep: Reputation: 30
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, 04:16 AM   #2
marquardl
Member
 
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 03:49 AM.
 
Old 04-18-2008, 05:14 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

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

Code:
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
60000
jschiwal@hpamd64:~> echo $UID_MIN
1000
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:
Code:
awk 'BEGIN { FS=":" } int($3) >= '$UID_MIN' && int($3) <= '$UID_MAX' { print $1 }' /etc/passwd
jschiwal
testuser
tuser
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:
Code:
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.
 
  


Reply


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


All times are GMT -5. The time now is 05:26 PM.

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