How to transfer user accounts to a new Linux machine?

From a cyberciti.biz article:

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.

You need to backup all of the above files and directories from old server to new Linux server.


How many users are we talking about?

If it's just a few, it would be much safer to just run "useradd" on the new system, making sure to specify the same uid and gid for each user you're migrating.

Then, once accounts have been created on the new machine with the same uid/gid, disable logins on the old machine, and use rsync to transfer over their home directories. The only remaining step would be to reset their passwords after the migration.

The issue with copying things like /etc/passwd and /etc/group is that if you mess things up, you'll completely block yourself (or root) from logging in to the new system. Additionally, different unix flavors might have different interpretations of these files, so you should be very careful. One small slip and you could open up logins as user "guest" or any number of other security holes.