How can I rescue my passwd file after corrupting it (and why
does it still work) ?
Ruben de Groot
mail25 at bzerk.org
Sun Nov 22 13:41:59 UTC 2009
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
More information about the freebsd-questions
mailing list