Migrate Services and Users and Groups from a Linux Server to Another Linux Server

Mindwatering Incorporated

Author: Tripp W Black

Created: 08/10/2015 at 11:00 AM

 

Category:
Linux
Installation

Topic:
Steps to migrate user and group accounts from one Linux server to another one.


Prereq. Steps:
1. Backup both source (old) and target (new) servers.


2. Check services in use on old servers and confirm new server is running same services (as desired).

a. Linux with Check System-V
# which service
/usr/sbin/service
(If nothing returned, system using different init. If Ubuntu, it's usually Upstart.)

# service --status-all
+ = running/started, - = stopped, ? = unknown

b. Ubuntu w/ chkconfig installed:
# chkconfig --list
on= running/started, off = stopped

c. Linux/Ubuntu w/ sysv-rc-conf installed:
# sysv-rc-conf --list
on= running/started, off = stopped

d. Ubuntu w/ Upstart
# which initctl
/sbin/initctl

# initctl list

# initctl show-config

e. Linux w/SystemD
# systemctl list-units -t service

# systemctl list-units -t target


3a. Update target system with yum / apt-get
# yum update
# yum upgrade
or
$ sudo apt-get update
$ sudo apt-get upgrade

3b. Update sources list on new Linux server for any custom sites still wanted.
Ubuntu:
$ sudo ls /etc/apt/sources-list
$ sudo ls /etc/apt/sources.list.d

CentOS / RedHat:
# yum repolist enabled
# yum config-manager --add-repo server.url.to.add


4. Install Services desired on target/new server
$ sudo apt-get install servicepackagename
or
$ yum install servicepackagename


5. Copy the config files for each server. Standard folders below:
Note: Make backups of the config files/folders beforehand incase you need to compare folder paths before and after. Folder paths DO CHANGE between releases of packages sometimes.

Web Data - Copy folder: /var/www/
Web Configuration - Copy folder: /etc/apache2/
Web PHP Config - Copy folder: /etc/php5/

MySQL - Copy folder: /etc/mysql/
MySQL database dump on source server:
$ sudo mysqldump -Q -q -e -R --add-drop-table -A -u root -mysqlpassword > /root/mysqldatabase_name.db
(repeat for each database)
MySQL database import on target:
$ sudo mysql -u root -mysqlpassword < /root/mysqldatabase_name.db

For SAMBA, there are significant files differences between versions / distros. Update the target/new server's configuration file, by finding the sections/lines to update, and then add the share sections to the bottom.
/etc/samba/smb.conf
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-samba-servers.html

6. For UFW Ubuntu firewall:
Copy the user6.rules and user.rules files from the /lib/ufw/ folder to the new server and disable and renable the ufw firewall for the rules to take effect.


User and Groups Migration
1. Confirm / locate the following user and group config files:

/etc/passwd:
User IDs and basic attributes. It contains username, user ID/number and primary group IDs/numbers, home directory, and default shell.

/etc/shadow:
Password info and hash for each user. Each user has his/her own line. Includes info about password policies.

/etc/group:
Group names and IDs/numbers. Includes any usernames that use this as a supplementary group.

/etc/gshadow:
Contains the group, a password used by non-group members to access the group, group (list) administrators and non-administrators. Each group has its own line in the file.

DO NOT JUST COPY THE FILES OVER. The group and user IDs will very likely not match.

2. Trim out the lines desired out of the file passwd and group files. Look in the files to see which ID ranges are being used for the users; use the 3rd column. User IDs typically go start at 500 or 1000. Leave out the root entry and the system processes above and below the users. Also leave out the nobody entry (typically user 65534).

Examples:
awk -v LIMIT=1001 -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/passwd.sync
awk -v LIMIT=1001 -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/group.sync
awk -v LIMIT=1001 -F: '($3>=LIMIT) && ($3!=35534) {print $1}' /etc/passwd | tee - | egrep -f - /etc/shadow > /root/shadow.sync
awk -v LIMIT=1001 -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/group | tee - | egrep -f - /etc/gshadow > /root/gshadow.sync

Now add them in the correct locations within the new servers files. (Don't append them. Put them in the correct order placement.

Use vipw to edit the /etc/passwd file.
Use vipr to edit the /etc/group file.
Use vipw -s to edit the /etc/shadow file.
Use vipw -g to edit the /etc/gshadow file.

- or -
Add each one via command line. Examples:
$ sudo useradd -d /home/userid -m userid -u 1018
(where userid is the login ID and 1018 is the user UID)
$ sudo groupadd -g 500 machines
$ sudo useradd -u 1015 –g 500 –d /dev/null –c "machineshortname$ machine account" –s /bin/false machineshortname$


3. Copy all the /home directories for all the users to the new server.
If the user IDs (numbers and shortname/ID) are the same. You should not have to run a chown / chgrp on the folders. However, verify after copying regardless.




previous page

×