Thursday, August 16, 2012

Migrate user files from old machine to new machine


Following files/dirs are required for traditional Linux user management:
/etc/passwd - contains various pieces of information for each user account
/etc/shadow - contains the encrypted password information for user's accounts and optional the password aging information.

/etc/group - defines the groups to which users belong
/etc/gshadow - group shadow file (contains the encrypted password for group)
/var/spool/mail - Generally user emails are stored here.
/home - All Users data is stored here.


Pre
  1. mkdir /move

Backup user account
  1. We only want to keep user account except account used by system, so we only backup account with UID LIMIT >= 500.
        awk -v LIMIT=500 -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /move/passwd

Backup Groups 

        awk -v LIMIT=500 -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /move/group

Backup User & Group password 
  1. awk -v LIMIT=500 -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /move/shadow
  2. cp /etc/gshadow /move/gshadow

Backup /home & /var/spool/mail
  1. tar -zcvpf /move/home.tar.gz /home
  2. tar -zcvpf /move/mail.tar.gz /var/spool/mail
[src] http://www.cyberciti.biz/faq/howto-move-migrate-user-accounts-old-to-new-server/

No comments:

Post a Comment