From owner-freebsd-questions@FreeBSD.ORG Sun Nov 22 13:41:59 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B6983106566C for ; Sun, 22 Nov 2009 13:41:59 +0000 (UTC) (envelope-from mail25@bzerk.org) Received: from ei.bzerk.org (tunnel490.ipv6.xs4all.nl [IPv6:2001:888:10:1ea::2]) by mx1.freebsd.org (Postfix) with ESMTP id 2FC858FC0A for ; Sun, 22 Nov 2009 13:41:58 +0000 (UTC) Received: from ei.bzerk.org (BOFH@localhost [127.0.0.1]) by ei.bzerk.org (8.14.2/8.14.2) with ESMTP id nAMDfsLI050569; Sun, 22 Nov 2009 14:41:54 +0100 (CET) (envelope-from mail25@bzerk.org) Received: (from bulk@localhost) by ei.bzerk.org (8.14.2/8.14.2/Submit) id nAMDfraf050568; Sun, 22 Nov 2009 14:41:53 +0100 (CET) (envelope-from mail25@bzerk.org) Date: Sun, 22 Nov 2009 14:41:53 +0100 From: Ruben de Groot To: Matthew Seaman Message-ID: <20091122134153.GA50521@ei.bzerk.org> Mail-Followup-To: Ruben de Groot , Matthew Seaman , George Sanders , freebsd-questions@freebsd.org References: <739790.37971.qm@web111611.mail.gq1.yahoo.com> <4B08F2C8.2040901@infracaninophile.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B08F2C8.2040901@infracaninophile.co.uk> User-Agent: Mutt/1.4.2.3i X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0.1 (ei.bzerk.org [127.0.0.1]); Sun, 22 Nov 2009 14:41:57 +0100 (CET) Cc: George Sanders , freebsd-questions@freebsd.org Subject: Re: How can I rescue my passwd file after corrupting it (and why does it still work) ? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Nov 2009 13:41:59 -0000 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