Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 13 Feb 2003 13:23:00 +0100
From:      Miguel Mendez <flynn@energyhq.homeip.net>
To:        Willie Viljoen <will@unfoldings.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Moving user accounts from one system to another
Message-ID:  <20030213132300.583b8fe7.flynn@energyhq.homeip.net>
In-Reply-To: <200302131355.04993.will@unfoldings.net>
References:  <200302131355.04993.will@unfoldings.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--=.hms?H3/RZ'Q,V0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Thu, 13 Feb 2003 13:55:04 +0200
Willie Viljoen <will@unfoldings.net> wrote:

> Does anybody know of a quick and (relatively) easy way of moving user 
> accounts between two machines?
 
> I need to move (roughly 200) user accounts from the old server to the
> other machine. I can't just copy master.password and the data, the
> UIDs used on the old server may conflict and clash with UIDs on the
> other server.

My two cents (hacked in 2 mins, verify before trying)

1) Copy the password file from the old machine to a temp dir in the new.
2) Trim out root,toor,daemon,nobody etc
3) csh style (change to for user in ... for sh-esque shells)

$ foreach user (`cat passwd`)
echo $user|awk -F: '{print "useradd -n " $1 " -c \"" $5 "\"" " -m " " -s" $7}'|xargs pw
end

This will add all those users with their name and shell. Customize if
those users don't have home dir, etc. You can do something similar for
groups. Then copy the homedirs and do a simple loop to set the proper
uid:gid.
E.g, if each user has its own group it becomes quite trivial.

$ cd /home
$ foreach user (*)
chown -R $user:$user $user
end

Now the encrypted passwords. You need a copy of master.passwd and a
similar loop to the one we used before, except you should something like
sed this time. The substitution command could look like this: 

sed -i -e 's@user:\*:@user:e29rSoyJdLHFIbIt1:@' master.passwd

Building the argument string with awk should be quite trivial. Don't forget to run
pwd_mkdb after you're done!

Also, try this with temp files before, of course :)

Cheers,
-- 
        Miguel Mendez - flynn@energyhq.homeip.net
        GPG Public Key :: http://energyhq.homeip.net/files/pubkey.txt
        EnergyHQ :: http://www.energyhq.tk
        Of course it runs NetBSD!

--=.hms?H3/RZ'Q,V0
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (NetBSD)

iD8DBQE+S44nnLctrNyFFPERAnX9AKC9yz5JM5fy69Acrt59fyzu12+a3QCgnReg
9O/U2zPvnmiP7C5DHoWbo9o=
=KaJ0
-----END PGP SIGNATURE-----

--=.hms?H3/RZ'Q,V0--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030213132300.583b8fe7.flynn>