Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Nov 2009 14:41:53 +0100
From:      Ruben de Groot <mail25@bzerk.org>
To:        Matthew Seaman <m.seaman@infracaninophile.co.uk>
Cc:        George Sanders <gosand1982@yahoo.com>, freebsd-questions@freebsd.org
Subject:   Re: How can I rescue my passwd file after corrupting it (and why does	it still work) ?
Message-ID:  <20091122134153.GA50521@ei.bzerk.org>
In-Reply-To: <4B08F2C8.2040901@infracaninophile.co.uk>
References:  <739790.37971.qm@web111611.mail.gq1.yahoo.com> <4B08F2C8.2040901@infracaninophile.co.uk>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Nov 22, 2009 at 08:14:00AM +0000, Matthew Seaman typed:
> 
> % pw user show -n matthew
> matthew:*:1001:1001::0:0:Matthew Seaman:/home/matthew:/bin/tcsh
> 
> prints out the master.passwd entry for the user account but *without* the
> password crypt-text.  You can use:
> 
>  % pw user show -a 
> 
> to get a list of all users.  This should use spwd.db rather than the 
> original
> flat files -- it will enumerate all users from LDAP or NIS if your machine 
> is
> configured to use those.  Unfortunately, you will have to merge in the 
> crypted
> password strings by hand or else get all your users to set new passwords.

Another way to recover is using perl:

while ( ($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell,$expire) = getpwent ) {
        print $name . ":" . $passwd . ":" . $uid . ":" . $gid . "::0:" . $expire . ":" . $gcos . ":" .$dir . ":" . $shell . "\n";
}

This will generate a file you can use to replace master.passwd, without
login class or passwd last changed information (if you use that) but
including the encrypted password.

Ruben



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