From owner-freebsd-questions@FreeBSD.ORG Fri Nov 21 09:44:36 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 361E916A4CE for ; Fri, 21 Nov 2003 09:44:36 -0800 (PST) Received: from munk.nu (mail.munk.nu [213.152.51.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id D724043FE3 for ; Fri, 21 Nov 2003 09:44:30 -0800 (PST) (envelope-from munk@munk.nu) Received: from munk by munk.nu with local (Exim 4.24; FreeBSD) id 1ANFKX-000IJy-6O for questions@freebsd.org; Fri, 21 Nov 2003 17:44:29 +0000 Date: Fri, 21 Nov 2003 17:44:29 +0000 From: Jez Hancock To: questions@freebsd.org Message-ID: <20031121174429.GA69747@users.munk.nu> Mail-Followup-To: questions@freebsd.org References: <3FBD97CE.8982F285@ene.asda.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3FBD97CE.8982F285@ene.asda.gr> User-Agent: Mutt/1.4.1i Sender: User Munk Subject: Re: How can I set a password from STDIN? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Nov 2003 17:44:36 -0000 On Fri, Nov 21, 2003 at 06:42:54AM +0200, Lefteris Tsintjelis wrote: > Hi, > > Would anyone know how can I set or change a password from STDIN? Neither > passwd or pw seem to accept STDIN. As someone else mentioned, use -h switch to pw to modify a user password command line using pw. As an example a recent PHP application I worked on I added this as a comment: /* use popen to create a stream to the command: pw adduser -q -u user -g group \ -s shell -d /home/user -c comment -h 0 and then write the password to the file pointer created by popen. This effectively adds the user to the passwd database whilst at same time setting the password. This saves listing the password in 'ps' listings. */ // adduser command: $pw_cmd = $cfg['prog']['pw']." useradd ".$data["username"] ." -g g".$data["id"] ." -s $shell " ." -d ".$data["root"] ." -c \"".$data["name"]."\"" ." -h 0"; // Open a uni-directional stream to the command: $fp = popen($pw_cmd, "w"); // Execute the command, passing the $data["password"] to it: fwrite($fp, $data["password"]); // Close the pipe: fclose($fp); -- Jez Hancock - System Administrator / PHP Developer http://munk.nu/