Monday, April 25, 2011

Migrating user accounts in FreeBSD.

I make a lot of servers.  When it comes time for backups, upgrades, updates and general data security, I find myself moving users from one box to another quite frequently.  Typing in all of those usernames and passwords (that you probably have no way to know) might present a problem.  Luckily FreeBSD makes this process quite simple.  The first step (in anything computer-related) is to back up what you're about to touch.  This is as simple as these 3 commands on the server that is to host the new accounts:
cp /etc/master.passwd /etc/master.passwd.orig
cp /etc/passwd /etc/passwd.orig
cp /etc/group /etc/group.orig

Then copy these same files from the 'old' machine, you can use 'scp' or whatever to copy them.  If you're unsure how to do this, send me a message; that would be a whole separate post.  Once you get the files to the 'new' machine, copy them to the /etc folder overwriting what is there.  Type the following command to import all of the users:

pwd_mkdb /etc/master.passwd
(NOTE: THIS WILL MAKE THE USER LIST THE SAME AS THE 'OLD' MACHINE; ANY ACCOUNT THAT IS NOT ON THE OLD MACHINE WILL NOT EXIST; ROOT PASSWD WILL CHANGE TO WHAT 'OLD' IS SET TO.)

That is it. All of the users that could log into the 'old' server can now log onto the 'new' server with their same passwords.

No comments:

Post a Comment